File size: 1,360 Bytes
f3d5c36
58a6f69
67e0e4f
58a6f69
 
 
 
49fb9a3
29c62a9
 
67e0e4f
 
 
f3d5c36
 
 
 
 
67e0e4f
9968ab7
67e0e4f
 
 
 
 
 
 
 
f3d5c36
67e0e4f
 
 
 
 
 
 
 
 
 
29c62a9
 
 
58a6f69
33ab927
29c62a9
 
 
67e0e4f
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
import gradio as gr
import replicate
import requests
import os
import uuid

# Set your Replicate API token
os.environ["REPLICATE_API_TOKEN"] = "r8_FqBcLY8OR6F3Fsf4D4fT415tb1CN3790UGzYE"

def generate_3d(prompt):
    try:
        output = replicate.run(
            "openai/shap-e:9c9ecb8d35d0cc0ecde68b8a0d4a2f94f2bc6ee9393e8c3d76c44d7c0d75b1f9",
            input={
                "prompt": prompt,
                "guidance_scale": 15,
                "num_inference_steps": 64
            }
        )
        print("Replicate output:", output)

        if not output or not isinstance(output, list):
            return "Error: No model output."

        glb_url = output[0]
        response = requests.get(glb_url)

        if response.status_code != 200:
            return f"Download failed: {response.status_code}"

        file_name = f"{uuid.uuid4()}.glb"
        with open(file_name, 'wb') as f:
            f.write(response.content)

        return file_name

    except Exception as e:
        return f"Generation failed: {str(e)}"

with gr.Blocks() as demo:
    gr.Markdown("## 3D Model Generator (Text to 3D)")
    prompt = gr.Textbox(label="Prompt", placeholder="e.g. A sci-fi sword")
    output = gr.Model3D(label="Generated 3D Model")

    btn = gr.Button("Generate")
    btn.click(fn=generate_3d, inputs=prompt, outputs=output)

demo.launch()