File size: 1,961 Bytes
5f85653 d538199 5f85653 9b4a1c9 69cbe68 9b4a1c9 0758d87 9b4a1c9 12366d3 9b4a1c9 2a5c433 9b4a1c9 2a5c433 9b4a1c9 2a5c433 89dff02 d614a76 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
import gradio as gr
import spaces
# from gradio_litmodel3d import LitModel3D
@spaces.GPU
def greet(n):
print(zero.device) # <-- 'cuda:0' 🤗
return f"Hello {zero + n} Tensor"
import gradio as gr
with gr.Blocks() as demo:
gr.Markdown("## 3D Model Viewer")
model = gr.Model3D(
label="3D Model Viewer",
# value="https://modelviewer.dev/shared-assets/models/Astronaut.glb", # 示例模型
clear_color=(0.9, 0.9, 0.9, 1) # 先设置亮色背景提升基础亮度
)
model2 = gr.Model3D(
label="3D Model Viewer2",
# value="https://modelviewer.dev/shared-assets/models/Astronaut.glb", # 示例模型
clear_color=(0.9, 0.9, 0.9, 1) # 先设置亮色背景提升基础亮度
)
# demo.load(
# js="""
# () => {
# // 等待组件加载完成(避免选择器找不到元素)
# const observer = new MutationObserver(() => {
# const viewer = document.querySelector('[data-testid="model3d-component"] .model-viewer');
# if (viewer) {
# const scene = viewer.modelView.scene;
# observer.disconnect(); // 找到后停止观察
# // 添加环境光(白色,强度 1.5)
# const ambientLight = new THREE.AmbientLight(0xffffff, 1.5);
# scene.add(ambientLight);
# // 添加方向光(从右上方照射,模拟自然光)
# const directionalLight = new THREE.DirectionalLight(0xffffff, 1.8);
# directionalLight.position.set(8, 10, 5); // 调整光源位置
# scene.add(directionalLight);
# }
# });
# observer.observe(document.body, { childList: true, subtree: true });
# }
# """
# )
if __name__ == "__main__":
demo.launch()
|