Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -41,6 +41,11 @@ def generate_3d_avatar(sketch_image, height, weight, muscle, gender, breast):
|
|
| 41 |
if sketch_image is None:
|
| 42 |
return None, None
|
| 43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
# Build prompt
|
| 45 |
body = f"{gender}, {height} height, {weight} build, {muscle} muscles"
|
| 46 |
if gender == "female":
|
|
@@ -76,13 +81,14 @@ def generate_3d_avatar(sketch_image, height, weight, muscle, gender, breast):
|
|
| 76 |
|
| 77 |
except Exception as e:
|
| 78 |
if attempt == 2:
|
| 79 |
-
|
|
|
|
| 80 |
time.sleep(15)
|
| 81 |
|
| 82 |
return None, None
|
| 83 |
|
| 84 |
|
| 85 |
-
# =============== UI
|
| 86 |
with gr.Blocks(title="SketchToLife") as demo:
|
| 87 |
gr.Markdown("# SketchToLife β Photo β Sketch β Animated 3D Avatar (100% Free!)")
|
| 88 |
gr.Markdown("Works with **humans, dogs, cats, anything** β Instant sketch + Rigged 3D download")
|
|
@@ -91,7 +97,9 @@ with gr.Blocks(title="SketchToLife") as demo:
|
|
| 91 |
with gr.Column():
|
| 92 |
inp = gr.Image(label="Upload Photo", type="pil", height=420)
|
| 93 |
btn1 = gr.Button("Generate Clean Sketch", variant="secondary", size="lg")
|
| 94 |
-
|
|
|
|
|
|
|
| 95 |
|
| 96 |
with gr.Column():
|
| 97 |
gr.Markdown("### Customize 3D Body")
|
|
@@ -110,9 +118,9 @@ with gr.Blocks(title="SketchToLife") as demo:
|
|
| 110 |
btn1.click(photo_to_sketch, inputs=inp, outputs=out_sketch)
|
| 111 |
btn2.click(generate_3d_avatar, inputs=[out_sketch, h, w, m, g, b], outputs=[view3d, download])
|
| 112 |
|
| 113 |
-
|
| 114 |
-
demo.launch(
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
)
|
|
|
|
| 41 |
if sketch_image is None:
|
| 42 |
return None, None
|
| 43 |
|
| 44 |
+
# --- FIX: Convert NumPy array (from Gradio) back to PIL Image ---
|
| 45 |
+
if isinstance(sketch_image, np.ndarray):
|
| 46 |
+
sketch_image = Image.fromarray(sketch_image.astype('uint8'))
|
| 47 |
+
# ----------------------------------------------------------------
|
| 48 |
+
|
| 49 |
# Build prompt
|
| 50 |
body = f"{gender}, {height} height, {weight} build, {muscle} muscles"
|
| 51 |
if gender == "female":
|
|
|
|
| 81 |
|
| 82 |
except Exception as e:
|
| 83 |
if attempt == 2:
|
| 84 |
+
# Raise Gradio error so it appears in the UI
|
| 85 |
+
raise gr.Error(f"3D generation failed: {e}")
|
| 86 |
time.sleep(15)
|
| 87 |
|
| 88 |
return None, None
|
| 89 |
|
| 90 |
|
| 91 |
+
# =============== UI ===============
|
| 92 |
with gr.Blocks(title="SketchToLife") as demo:
|
| 93 |
gr.Markdown("# SketchToLife β Photo β Sketch β Animated 3D Avatar (100% Free!)")
|
| 94 |
gr.Markdown("Works with **humans, dogs, cats, anything** β Instant sketch + Rigged 3D download")
|
|
|
|
| 97 |
with gr.Column():
|
| 98 |
inp = gr.Image(label="Upload Photo", type="pil", height=420)
|
| 99 |
btn1 = gr.Button("Generate Clean Sketch", variant="secondary", size="lg")
|
| 100 |
+
# Explicitly setting type="pil" here is good practice,
|
| 101 |
+
# but the function fix above handles it regardless.
|
| 102 |
+
out_sketch = gr.Image(label="Your Sketch", height=420, type="pil")
|
| 103 |
|
| 104 |
with gr.Column():
|
| 105 |
gr.Markdown("### Customize 3D Body")
|
|
|
|
| 118 |
btn1.click(photo_to_sketch, inputs=inp, outputs=out_sketch)
|
| 119 |
btn2.click(generate_3d_avatar, inputs=[out_sketch, h, w, m, g, b], outputs=[view3d, download])
|
| 120 |
|
| 121 |
+
if __name__ == "__main__":
|
| 122 |
+
demo.launch(
|
| 123 |
+
server_name="0.0.0.0",
|
| 124 |
+
server_port=7860,
|
| 125 |
+
ssr_mode=False # Disabled SSR as hinted in your logs
|
| 126 |
+
)
|