Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,22 +1,33 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
|
|
|
| 3 |
|
|
|
|
| 4 |
API_URL = "https://api-inference.huggingface.co/models/TripoSR/TripoSR"
|
| 5 |
-
headers = {"Authorization": "Bearer
|
| 6 |
|
| 7 |
def generate_3d(image):
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
|
|
|
| 14 |
iface = gr.Interface(
|
| 15 |
fn=generate_3d,
|
| 16 |
inputs=gr.Image(type="filepath", label="Upload 2D Image"),
|
| 17 |
outputs="model3d",
|
| 18 |
title="Scan Spectrum - 2D to 3D Converter",
|
| 19 |
-
description="Upload any 2D image to
|
| 20 |
)
|
| 21 |
|
|
|
|
| 22 |
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
+
import os
|
| 4 |
|
| 5 |
+
# Get your API key securely from Hugging Face Space Secrets
|
| 6 |
API_URL = "https://api-inference.huggingface.co/models/TripoSR/TripoSR"
|
| 7 |
+
headers = {"Authorization": f"Bearer {os.getenv('HF_API_KEY')}"}
|
| 8 |
|
| 9 |
def generate_3d(image):
|
| 10 |
+
try:
|
| 11 |
+
# Send image to TripoSR model API
|
| 12 |
+
with open(image, "rb") as f:
|
| 13 |
+
response = requests.post(API_URL, headers=headers, files={"file": f})
|
| 14 |
+
|
| 15 |
+
# Check response
|
| 16 |
+
if response.status_code == 200:
|
| 17 |
+
return response.content
|
| 18 |
+
else:
|
| 19 |
+
return f"Error: {response.text}"
|
| 20 |
+
except Exception as e:
|
| 21 |
+
return f"An error occurred: {str(e)}"
|
| 22 |
|
| 23 |
+
# Build Gradio interface
|
| 24 |
iface = gr.Interface(
|
| 25 |
fn=generate_3d,
|
| 26 |
inputs=gr.Image(type="filepath", label="Upload 2D Image"),
|
| 27 |
outputs="model3d",
|
| 28 |
title="Scan Spectrum - 2D to 3D Converter",
|
| 29 |
+
description="Upload any 2D image to generate a realistic 3D model that you can rotate and zoom.",
|
| 30 |
)
|
| 31 |
|
| 32 |
+
# Launch the app
|
| 33 |
iface.launch()
|