Spaces:
Sleeping
Sleeping
File size: 1,112 Bytes
cac9916 7e0fe33 cac9916 1414894 cac9916 7e0fe33 cac9916 7e0fe33 b5c2cd4 7e0fe33 cac9916 b5c2cd4 cac9916 b5c2cd4 cac9916 b5c2cd4 cac9916 b5c2cd4 cac9916 |
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 |
import gradio as gr
import requests
import os
# Get Hugging Face API key from the secret you just saved
API_URL = "https://api-inference.huggingface.co/models/TripoSR/TripoSR"
headers = {"Authorization": f"Bearer {os.getenv('HF_API_KEY')}"}
def generate_3d(image):
try:
with open(image, "rb") as f:
response = requests.post(API_URL, headers=headers, files={"file": f})
if response.status_code == 200:
# Save the model locally
output_path = "output.glb"
with open(output_path, "wb") as out_file:
out_file.write(response.content)
return output_path # Gradio will let user download it
else:
return f"Error: {response.text}"
except Exception as e:
return f"An error occurred: {str(e)}"
iface = gr.Interface(
fn=generate_3d,
inputs=gr.Image(type="filepath", label="Upload 2D Image"),
outputs="file", # change here
title="Scan Spectrum - 2D to 3D Converter",
description="Upload any 2D image to generate a realistic 3D model you can download.",
)
iface.launch()
|