3D / app.py
fandimuhammads's picture
Update app.py
71bcbad verified
import os
import gradio as gr
from huggingface_hub import InferenceClient
import tempfile
import trimesh
HF_TOKEN = os.getenv("HF_TOKEN") # token environment
client = InferenceClient(token=HF_TOKEN)
def generate_3d(prompt):
result = client.text_to_mesh(
model="Webaverse/Stable-Dreamfusion",
inputs={"prompt": prompt, "num_steps": 100},
)
mesh_bytes = result["output"] # raw mesh bytes
temp = tempfile.NamedTemporaryFile(delete=False, suffix=".ply")
temp.write(mesh_bytes)
temp.flush()
# optionally convert to .glb
mesh = trimesh.load(temp.name)
glb_path = temp.name.replace(".ply", ".glb")
mesh.export(glb_path)
return glb_path
iface = gr.Interface(
fn=generate_3d,
inputs=gr.Textbox(label="Prompt Game Asset"),
outputs=gr.Model3D(label="Generated 3D Asset (.glb)"),
title="Text‑to‑3D Game Asset (Dreamfusion)",
description="Masukkan prompt, hasil akan berupa file .glb yang siap impor ke game engine."
)
iface.launch()