File size: 1,133 Bytes
28b953a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

import shutil
import gradio as gr
from gradio_client import Client

# Define a function to generate and return the .glb file path
def generate_3d_model(prompt):
    # Initialize Gradio client for Shap-E API
    client = Client("hysts/Shap-E")
    result = client.predict(
        prompt=prompt,
        seed=0,
        guidance_scale=15,
        num_inference_steps=64,
        api_name="/text-to-3d"
    )

    # Define the path to save the .glb file
    glb_path = "generated_model.glb"

    # Copy the result file locally if it's a temp file
    if result.startswith("/tmp"):
        shutil.copy(result, glb_path)
    else:
        # Otherwise, download the file if it's a URL
        import requests
        response = requests.get(result)
        with open(glb_path, "wb") as f:
            f.write(response.content)

    return glb_path

# Create the Gradio interface
interface = gr.Interface(
    fn=generate_3d_model,
    inputs="text",
    outputs=gr.Model3D(label="Generated 3D Model"),
    title="3D Model Generator",
    description="Enter a prompt to generate a 3D model."
)

# Launch the Gradio app
interface.launch()