|
import gradio as gr |
|
import replicate |
|
import requests |
|
import os |
|
import uuid |
|
|
|
|
|
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() |