Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,8 +8,9 @@ import time
|
|
| 8 |
from gradio_client import Client, file
|
| 9 |
|
| 10 |
# --- CONFIGURATION ---
|
| 11 |
-
#
|
| 12 |
-
|
|
|
|
| 13 |
|
| 14 |
def photo_to_sketch(image):
|
| 15 |
"""Instant local sketch β always returns PIL Image"""
|
|
@@ -36,8 +37,8 @@ def photo_to_sketch(image):
|
|
| 36 |
return sketch_pil.convert("RGB")
|
| 37 |
|
| 38 |
def generate_3d_avatar(sketch_image, height, weight, muscle, gender, breast):
|
| 39 |
-
"""Generate rigged 3D model using the remote
|
| 40 |
-
print("-> Starting 3D Generation...")
|
| 41 |
|
| 42 |
if sketch_image is None:
|
| 43 |
raise gr.Error("Please upload an image and generate a sketch first!")
|
|
@@ -57,26 +58,38 @@ def generate_3d_avatar(sketch_image, height, weight, muscle, gender, breast):
|
|
| 57 |
print(f"-> Connecting to {REMOTE_MODEL_ID}...")
|
| 58 |
client = Client(REMOTE_MODEL_ID)
|
| 59 |
|
| 60 |
-
# 3. Send
|
|
|
|
| 61 |
print("-> Sending request to remote GPU...")
|
|
|
|
|
|
|
| 62 |
result_path = client.predict(
|
| 63 |
-
file(sketch_path), #
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
|
|
|
| 67 |
)
|
| 68 |
|
| 69 |
-
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
except Exception as e:
|
| 73 |
print(f"-> Connection Error: {e}")
|
| 74 |
-
|
|
|
|
| 75 |
|
| 76 |
# =============== UI ===============
|
| 77 |
with gr.Blocks(title="SketchToLife") as demo:
|
| 78 |
-
gr.Markdown("# SketchToLife β Photo β Sketch β
|
| 79 |
-
gr.Markdown("**Status:** Connected to `
|
| 80 |
|
| 81 |
with gr.Row():
|
| 82 |
with gr.Column():
|
|
@@ -86,9 +99,7 @@ with gr.Blocks(title="SketchToLife") as demo:
|
|
| 86 |
|
| 87 |
with gr.Column():
|
| 88 |
gr.Markdown("### Customize 3D Body")
|
| 89 |
-
#
|
| 90 |
-
# are currently just placeholders in this specific workflow,
|
| 91 |
-
# but we keep them to prevent the code from crashing.
|
| 92 |
h = gr.Dropdown(["short", "average", "tall", "giant"], value="average", label="Height")
|
| 93 |
w = gr.Dropdown(["slim", "average", "curvy", "heavy"], value="average", label="Weight")
|
| 94 |
m = gr.Dropdown(["slim", "fit", "muscular", "bodybuilder"], value="fit", label="Muscle")
|
|
@@ -103,7 +114,7 @@ with gr.Blocks(title="SketchToLife") as demo:
|
|
| 103 |
|
| 104 |
btn1.click(photo_to_sketch, inputs=inp, outputs=out_sketch)
|
| 105 |
|
| 106 |
-
#
|
| 107 |
btn2.click(generate_3d_avatar, inputs=[out_sketch, h, w, m, g, b], outputs=[view3d, download])
|
| 108 |
|
| 109 |
if __name__ == "__main__":
|
|
|
|
| 8 |
from gradio_client import Client, file
|
| 9 |
|
| 10 |
# --- CONFIGURATION ---
|
| 11 |
+
# The official TripoSR space is down (Runtime Error).
|
| 12 |
+
# We are switching to "InstantMesh" which is newer, better quality, and currently ONLINE.
|
| 13 |
+
REMOTE_MODEL_ID = "TencentARC/InstantMesh"
|
| 14 |
|
| 15 |
def photo_to_sketch(image):
|
| 16 |
"""Instant local sketch β always returns PIL Image"""
|
|
|
|
| 37 |
return sketch_pil.convert("RGB")
|
| 38 |
|
| 39 |
def generate_3d_avatar(sketch_image, height, weight, muscle, gender, breast):
|
| 40 |
+
"""Generate rigged 3D model using the remote InstantMesh Space"""
|
| 41 |
+
print(f"-> Starting 3D Generation using {REMOTE_MODEL_ID}...")
|
| 42 |
|
| 43 |
if sketch_image is None:
|
| 44 |
raise gr.Error("Please upload an image and generate a sketch first!")
|
|
|
|
| 58 |
print(f"-> Connecting to {REMOTE_MODEL_ID}...")
|
| 59 |
client = Client(REMOTE_MODEL_ID)
|
| 60 |
|
| 61 |
+
# 3. Send request to InstantMesh
|
| 62 |
+
# InstantMesh API: [Image, do_remove_background, sample_steps, seed]
|
| 63 |
print("-> Sending request to remote GPU...")
|
| 64 |
+
|
| 65 |
+
# We try the standard generate endpoint for InstantMesh
|
| 66 |
result_path = client.predict(
|
| 67 |
+
file(sketch_path), # Input image
|
| 68 |
+
True, # Remove background? (Yes, safer)
|
| 69 |
+
30, # Sample steps (30 is standard quality)
|
| 70 |
+
42, # Seed
|
| 71 |
+
api_name="/generate"
|
| 72 |
)
|
| 73 |
|
| 74 |
+
# InstantMesh returns a tuple, usually the GLB is the first item or named path
|
| 75 |
+
# If it returns a tuple/list, we take the first file path.
|
| 76 |
+
if isinstance(result_path, (list, tuple)):
|
| 77 |
+
final_glb = result_path[0]
|
| 78 |
+
else:
|
| 79 |
+
final_glb = result_path
|
| 80 |
+
|
| 81 |
+
print(f"-> Success! Received 3D model at: {final_glb}")
|
| 82 |
+
return final_glb, final_glb
|
| 83 |
|
| 84 |
except Exception as e:
|
| 85 |
print(f"-> Connection Error: {e}")
|
| 86 |
+
# Detailed error message for debugging
|
| 87 |
+
raise gr.Error(f"Remote AI Error: {e}. The InstantMesh space might be busy or changing APIs.")
|
| 88 |
|
| 89 |
# =============== UI ===============
|
| 90 |
with gr.Blocks(title="SketchToLife") as demo:
|
| 91 |
+
gr.Markdown("# SketchToLife β Photo β Sketch β 3D Avatar (InstantMesh)")
|
| 92 |
+
gr.Markdown(f"**Status:** Connected to `{REMOTE_MODEL_ID}` (High Quality GPU Model)")
|
| 93 |
|
| 94 |
with gr.Row():
|
| 95 |
with gr.Column():
|
|
|
|
| 99 |
|
| 100 |
with gr.Column():
|
| 101 |
gr.Markdown("### Customize 3D Body")
|
| 102 |
+
# Placeholders to keep UI consistent and prevent argument errors
|
|
|
|
|
|
|
| 103 |
h = gr.Dropdown(["short", "average", "tall", "giant"], value="average", label="Height")
|
| 104 |
w = gr.Dropdown(["slim", "average", "curvy", "heavy"], value="average", label="Weight")
|
| 105 |
m = gr.Dropdown(["slim", "fit", "muscular", "bodybuilder"], value="fit", label="Muscle")
|
|
|
|
| 114 |
|
| 115 |
btn1.click(photo_to_sketch, inputs=inp, outputs=out_sketch)
|
| 116 |
|
| 117 |
+
# Passing all 6 inputs to match the function definition
|
| 118 |
btn2.click(generate_3d_avatar, inputs=[out_sketch, h, w, m, g, b], outputs=[view3d, download])
|
| 119 |
|
| 120 |
if __name__ == "__main__":
|