xinjie.wang
commited on
Commit
·
6f3a7d2
1
Parent(s):
3157f9a
Add application file
Browse files
app.py
CHANGED
@@ -1,79 +1,35 @@
|
|
1 |
import gradio as gr
|
2 |
import spaces
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
@spaces.GPU
|
6 |
def greet(n):
|
7 |
print(zero.device) # <-- 'cuda:0' 🤗
|
8 |
return f"Hello {zero + n} Tensor"
|
9 |
|
10 |
-
import gradio as gr
|
11 |
-
import spaces
|
12 |
-
|
13 |
-
lighting_js = """
|
14 |
-
<script>
|
15 |
-
function addLightingToModel2() {
|
16 |
-
try {
|
17 |
-
// 仅选择第二个 model-3d(model2)
|
18 |
-
const model2Canvas = document.querySelector('gradio-app model-3d:nth-child(2) canvas');
|
19 |
-
if (!model2Canvas) {
|
20 |
-
console.error('Model2 canvas not found');
|
21 |
-
return;
|
22 |
-
}
|
23 |
-
const model3dElement = model2Canvas.closest('model-3d');
|
24 |
-
if (!model3dElement || !model3dElement.__vue__?.scene) {
|
25 |
-
console.error('Vue instance or scene not found for model2');
|
26 |
-
return;
|
27 |
-
}
|
28 |
-
const scene = model3dElement.__vue__.scene;
|
29 |
-
// 移除现有光源(可选,保持默认光照可跳过)
|
30 |
-
scene.children = scene.children.filter(child => !child.isLight);
|
31 |
-
// 添加环境光
|
32 |
-
const ambientLight = new THREE.AmbientLight(0xffffff, 1.2); // 高强度环境光
|
33 |
-
scene.add(ambientLight);
|
34 |
-
// 添加平行光
|
35 |
-
const directionalLight = new THREE.DirectionalLight(0xffffff, 0.8); // 高强度平行光
|
36 |
-
directionalLight.position.set(1, 1, 1).normalize();
|
37 |
-
scene.add(directionalLight);
|
38 |
-
console.log('Enhanced lighting added to model2');
|
39 |
-
} catch (error) {
|
40 |
-
console.error('Error adding lighting to model2:', error.message);
|
41 |
-
}
|
42 |
-
}
|
43 |
-
document.addEventListener('DOMContentLoaded', () => {
|
44 |
-
setTimeout(addLightingToModel2, 2000); // 延迟确保加载
|
45 |
-
});
|
46 |
-
</script>
|
47 |
-
"""
|
48 |
|
49 |
with gr.Blocks() as demo:
|
50 |
-
gr.Markdown("## 3D Model Viewer
|
51 |
-
gr.HTML(
|
52 |
-
|
53 |
-
|
54 |
-
model_input = gr.File(label="Upload 3D Model for Viewer 1 (.glb, .gltf)")
|
55 |
-
model = gr.Model3D(
|
56 |
label="3D Model Viewer 1",
|
57 |
-
clear_color=(0.9, 0.9, 0.9, 1)
|
58 |
-
|
59 |
-
model_input.change(
|
60 |
-
lambda x: gr.Model3D(value=x.name),
|
61 |
-
inputs=model_input,
|
62 |
-
outputs=model
|
63 |
)
|
64 |
-
|
65 |
-
# model2(提高亮度)
|
66 |
-
model_input2 = gr.File(label="Upload 3D Model for Viewer 2 (.glb, .gltf)")
|
67 |
model2 = gr.Model3D(
|
68 |
-
label="3D Model
|
69 |
-
clear_color=(0.9, 0.9, 0.9, 1),
|
70 |
-
|
71 |
-
model_input2.change(
|
72 |
-
lambda x: gr.Model3D(value=x.name),
|
73 |
-
inputs=model_input2,
|
74 |
-
outputs=model2
|
75 |
)
|
76 |
|
77 |
-
|
78 |
-
if __name__ == "__main__":
|
79 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import spaces
|
3 |
+
|
4 |
+
# 只对 id=model2 的组件下 canvas 生效
|
5 |
+
lighting_css = """
|
6 |
+
<style>
|
7 |
+
#model2 canvas {
|
8 |
+
filter: brightness(2.5) !important;
|
9 |
+
}
|
10 |
+
</style>
|
11 |
+
"""
|
12 |
|
13 |
@spaces.GPU
|
14 |
def greet(n):
|
15 |
print(zero.device) # <-- 'cuda:0' 🤗
|
16 |
return f"Hello {zero + n} Tensor"
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
with gr.Blocks() as demo:
|
20 |
+
gr.Markdown("## 3D Model Viewer")
|
21 |
+
gr.HTML(lighting_css) # 注入样式
|
22 |
+
|
23 |
+
model1 = gr.Model3D(
|
|
|
|
|
24 |
label="3D Model Viewer 1",
|
25 |
+
clear_color=(0.9, 0.9, 0.9, 1),
|
26 |
+
elem_id="model1"
|
|
|
|
|
|
|
|
|
27 |
)
|
28 |
+
|
|
|
|
|
29 |
model2 = gr.Model3D(
|
30 |
+
label="3D Model Viewer 2 (Brighter)",
|
31 |
+
clear_color=(0.9, 0.9, 0.9, 1),
|
32 |
+
elem_id="model2"
|
|
|
|
|
|
|
|
|
33 |
)
|
34 |
|
35 |
+
demo.launch()
|
|
|
|