Spaces:
Running
Running
curryporkchop
commited on
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
import shutil
|
3 |
+
import gradio as gr
|
4 |
+
from gradio_client import Client
|
5 |
+
|
6 |
+
# Define a function to generate and return the .glb file path
|
7 |
+
def generate_3d_model(prompt):
|
8 |
+
# Initialize Gradio client for Shap-E API
|
9 |
+
client = Client("hysts/Shap-E")
|
10 |
+
result = client.predict(
|
11 |
+
prompt=prompt,
|
12 |
+
seed=0,
|
13 |
+
guidance_scale=15,
|
14 |
+
num_inference_steps=64,
|
15 |
+
api_name="/text-to-3d"
|
16 |
+
)
|
17 |
+
|
18 |
+
# Define the path to save the .glb file
|
19 |
+
glb_path = "generated_model.glb"
|
20 |
+
|
21 |
+
# Copy the result file locally if it's a temp file
|
22 |
+
if result.startswith("/tmp"):
|
23 |
+
shutil.copy(result, glb_path)
|
24 |
+
else:
|
25 |
+
# Otherwise, download the file if it's a URL
|
26 |
+
import requests
|
27 |
+
response = requests.get(result)
|
28 |
+
with open(glb_path, "wb") as f:
|
29 |
+
f.write(response.content)
|
30 |
+
|
31 |
+
return glb_path
|
32 |
+
|
33 |
+
# Create the Gradio interface
|
34 |
+
interface = gr.Interface(
|
35 |
+
fn=generate_3d_model,
|
36 |
+
inputs="text",
|
37 |
+
outputs=gr.Model3D(label="Generated 3D Model"),
|
38 |
+
title="3D Model Generator",
|
39 |
+
description="Enter a prompt to generate a 3D model."
|
40 |
+
)
|
41 |
+
|
42 |
+
# Launch the Gradio app
|
43 |
+
interface.launch()
|