Spaces:
Runtime error
Runtime error
Upload folder using huggingface_hub
Browse files- app.py +3 -0
- config.yml +2 -2
- javascript/animation.js +103 -0
- models/G_multilingual_70000.pth +3 -0
app.py
CHANGED
@@ -7,6 +7,9 @@ from presets import *
|
|
7 |
with gr.Blocks(css=customCSS) as demo:
|
8 |
exceed_flag = gr.State(value=False)
|
9 |
tmp_string = gr.Textbox(value="", visible=False)
|
|
|
|
|
|
|
10 |
character_area = gr.HTML(get_character_html("你好呀!我现在支持多语言了呢!"), elem_id="character_area")
|
11 |
with gr.Row(elem_id="tools_area"):
|
12 |
api_key_input = gr.Textbox(lines=1, max_lines=1, label="API Key:", placeholder="Comming Soon...", elem_classes="wonder-card", elem_id="api_key_input")
|
|
|
7 |
with gr.Blocks(css=customCSS) as demo:
|
8 |
exceed_flag = gr.State(value=False)
|
9 |
tmp_string = gr.Textbox(value="", visible=False)
|
10 |
+
gr.HTML("""
|
11 |
+
<script type="module" src="file=javascript/animation.js"></script>
|
12 |
+
""")
|
13 |
character_area = gr.HTML(get_character_html("你好呀!我现在支持多语言了呢!"), elem_id="character_area")
|
14 |
with gr.Row(elem_id="tools_area"):
|
15 |
api_key_input = gr.Textbox(lines=1, max_lines=1, label="API Key:", placeholder="Comming Soon...", elem_classes="wonder-card", elem_id="api_key_input")
|
config.yml
CHANGED
@@ -100,7 +100,7 @@ webui:
|
|
100 |
# 推理设备
|
101 |
device: "cpu"
|
102 |
# 模型路径
|
103 |
-
model: "models/
|
104 |
# 配置文件路径
|
105 |
config_path: "Data/config.json"
|
106 |
# 端口号
|
@@ -125,7 +125,7 @@ server:
|
|
125 |
# 注意,所有模型都必须正确配置model与config的路径,空路径会导致加载错误。
|
126 |
models:
|
127 |
- # 模型的路径
|
128 |
-
model: "models/
|
129 |
# 模型config.json的路径
|
130 |
config: "Data/config.json"
|
131 |
# 模型使用设备,若填写则会覆盖默认配置
|
|
|
100 |
# 推理设备
|
101 |
device: "cpu"
|
102 |
# 模型路径
|
103 |
+
model: "models/G_multilingual_70000.pth"
|
104 |
# 配置文件路径
|
105 |
config_path: "Data/config.json"
|
106 |
# 端口号
|
|
|
125 |
# 注意,所有模型都必须正确配置model与config的路径,空路径会导致加载错误。
|
126 |
models:
|
127 |
- # 模型的路径
|
128 |
+
model: "models/G_multilingual_70000.pth"
|
129 |
# 模型config.json的路径
|
130 |
config: "Data/config.json"
|
131 |
# 模型使用设备,若填写则会覆盖默认配置
|
javascript/animation.js
ADDED
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import * as THREE from 'three';
|
2 |
+
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
|
3 |
+
|
4 |
+
let scene, camera, renderer;
|
5 |
+
let bone_root, bone_skl_root, bone_body, bone_mouth, bone_mouth_1, bone_leaf_l, bone_leaf_r;
|
6 |
+
|
7 |
+
let clock = new THREE.Clock();
|
8 |
+
|
9 |
+
function init() {
|
10 |
+
// 创建场景、相机和渲染器
|
11 |
+
scene = new THREE.Scene();
|
12 |
+
camera = new THREE.PerspectiveCamera(35, window.innerWidth / window.innerHeight, 0.1, 1000);
|
13 |
+
renderer = new THREE.WebGLRenderer({ alpha: true });
|
14 |
+
renderer.setClearColor(0x000000, 0); // 第二个参数0表示完全透明
|
15 |
+
renderer.setSize(window.innerWidth, window.innerHeight);
|
16 |
+
document.body.appendChild(renderer.domElement);
|
17 |
+
|
18 |
+
// 添加光照
|
19 |
+
const pointLight1 = new THREE.PointLight(0xffffff, 10, 100);
|
20 |
+
pointLight1.position.set(1, 2, 2);
|
21 |
+
scene.add(pointLight1);
|
22 |
+
const pointLight2 = new THREE.PointLight(0xffffff, 10, 100);
|
23 |
+
pointLight2.position.set(-1, 2, 2);
|
24 |
+
scene.add(pointLight2);
|
25 |
+
const ambientLight = new THREE.AmbientLight(0xffffff, 1.0);
|
26 |
+
scene.add(ambientLight);
|
27 |
+
const directionalLight = new THREE.DirectionalLight(0xffffff, 1.0);
|
28 |
+
scene.add(directionalLight);
|
29 |
+
|
30 |
+
// 加载模型
|
31 |
+
const loader = new GLTFLoader();
|
32 |
+
loader.load('TalkingFlower.gltf', function (gltf) {
|
33 |
+
scene.add(gltf.scene);
|
34 |
+
gltf.scene.traverse(function (object) {
|
35 |
+
if (object.isBone) {
|
36 |
+
console.log(object); // 打印出骨骼信息,帮助你找到需要的骨骼
|
37 |
+
if (object.name === 'Root') bone_root = object;
|
38 |
+
if (object.name === 'Skl_Root') bone_skl_root = object;
|
39 |
+
if (object.name === 'Body') bone_body = object;
|
40 |
+
if (object.name === 'Mouth') bone_mouth = object;
|
41 |
+
if (object.name === 'Mouth_1') bone_mouth_1 = object;
|
42 |
+
if (object.name === 'Leaf_L') bone_leaf_l = object;
|
43 |
+
if (object.name === 'Leaf_R') bone_leaf_r = object;
|
44 |
+
}
|
45 |
+
});
|
46 |
+
bone_leaf_r.position.z = -0.1;
|
47 |
+
bone_leaf_l.position.z = -0.1;
|
48 |
+
bone_leaf_r.position.x = -0.02;
|
49 |
+
bone_leaf_l.position.x = 0.02;
|
50 |
+
bone_mouth.position.y -= 0.05;
|
51 |
+
bone_mouth.rotation.z -= 0.1;
|
52 |
+
}, undefined, function (error) {
|
53 |
+
console.error(error);
|
54 |
+
});
|
55 |
+
|
56 |
+
camera.position.z = 2;
|
57 |
+
camera.position.y = 0.25;
|
58 |
+
}
|
59 |
+
|
60 |
+
// 设置动画相关变量
|
61 |
+
let frameCount = 0;
|
62 |
+
const totalFrames = 120; // 一个循环的总帧数
|
63 |
+
|
64 |
+
function animate() {
|
65 |
+
requestAnimationFrame(animate);
|
66 |
+
// 更新帧计数器
|
67 |
+
frameCount++;
|
68 |
+
// 每120帧重置帧计数器
|
69 |
+
if (frameCount > totalFrames) {
|
70 |
+
frameCount = 0;
|
71 |
+
}
|
72 |
+
|
73 |
+
// 获取经过的时间(秒)
|
74 |
+
let elapsed = clock.getElapsedTime();
|
75 |
+
|
76 |
+
// 设置动画周期(120 帧约等于 2 秒)
|
77 |
+
let cycleDuration = 2;
|
78 |
+
|
79 |
+
// 计算当前周期的相对时间
|
80 |
+
let cycleTime = elapsed % cycleDuration;
|
81 |
+
|
82 |
+
// 使用正弦函数计算位置和角度
|
83 |
+
let theta = (cycleTime / cycleDuration) * Math.PI * 2;
|
84 |
+
let mouth_position = Math.sin(theta) * 0.02;
|
85 |
+
let mouth_angle = Math.cos(theta) * 0.1;
|
86 |
+
let leaf_angle = Math.sin(theta * 4) * 0.05;
|
87 |
+
|
88 |
+
// 应用变化到骨骼
|
89 |
+
bone_mouth_1.scale.set(1, 0.8, 0.75);
|
90 |
+
|
91 |
+
bone_mouth.position.x = mouth_position;
|
92 |
+
bone_mouth.rotation.z = mouth_angle;
|
93 |
+
|
94 |
+
bone_leaf_r.rotation.z = 9/8*Math.PI + leaf_angle;
|
95 |
+
bone_leaf_l.rotation.z = 1/8*Math.PI + leaf_angle;
|
96 |
+
|
97 |
+
renderer.render(scene, camera);
|
98 |
+
}
|
99 |
+
|
100 |
+
|
101 |
+
init();
|
102 |
+
animate();
|
103 |
+
|
models/G_multilingual_70000.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:6b96e3e1b2bc539db552a0ba273071dffe297bd9dad8c13d02e52c5d0ed35765
|
3 |
+
size 721511718
|