import gradio as gr | |
import spaces | |
# from gradio_litmodel3d import LitModel3D | |
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() | |