Spaces:
Running
on
Zero
Running
on
Zero
alltogether
Browse files
app.py
CHANGED
@@ -215,16 +215,31 @@ def step4_track(state):
|
|
215 |
|
216 |
return "✅ Pipeline complete!", image, state, gr.update(interactive=True)
|
217 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
218 |
# Build Gradio UI
|
219 |
demo = gr.Blocks()
|
220 |
-
|
221 |
with demo:
|
222 |
-
gr.Markdown("## Image Processing Pipeline")
|
223 |
-
gr.Markdown("Upload an image
|
224 |
with gr.Row():
|
225 |
with gr.Column():
|
226 |
image_in = gr.Image(label="Upload Image", type="numpy", height=512)
|
227 |
-
status = gr.Textbox(label="Status", lines=
|
228 |
state = gr.State({})
|
229 |
with gr.Column():
|
230 |
with gr.Row():
|
@@ -233,43 +248,16 @@ with demo:
|
|
233 |
with gr.Row():
|
234 |
uv_img = gr.Image(label="UV Map", height=256)
|
235 |
track_img = gr.Image(label="Tracking", height=256)
|
|
|
236 |
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
uv_map_btn = gr.Button("Step 3: UV Map", interactive=True)
|
241 |
-
track_btn = gr.Button("Step 4: Track", interactive=True)
|
242 |
-
|
243 |
-
# Define component list for reset
|
244 |
-
outputs_for_reset = [crop_img, normals_img, uv_img, track_img, status, state, preprocess_btn, normals_btn, uv_map_btn, track_btn]
|
245 |
-
|
246 |
-
# Pipeline execution logic
|
247 |
-
preprocess_btn.click(
|
248 |
-
fn=preprocess_image,
|
249 |
inputs=[image_in, state],
|
250 |
-
outputs=[status, crop_img,
|
251 |
-
)
|
252 |
-
normals_btn.click(
|
253 |
-
fn=step2_normals,
|
254 |
-
inputs=[state],
|
255 |
-
outputs=[status, normals_img, state, normals_btn, uv_map_btn]
|
256 |
-
)
|
257 |
-
uv_map_btn.click(
|
258 |
-
fn=step3_uv_map,
|
259 |
-
inputs=[state],
|
260 |
-
outputs=[status, uv_img, state, uv_map_btn, track_btn]
|
261 |
-
)
|
262 |
-
track_btn.click(
|
263 |
-
fn=step4_track,
|
264 |
-
inputs=[state],
|
265 |
-
outputs=[status, track_img, state, track_btn]
|
266 |
)
|
267 |
|
268 |
-
|
269 |
-
image_in.upload(fn=reset_all, inputs=None, outputs=outputs_for_reset)
|
270 |
|
271 |
-
# ------------------------------------------------------------------
|
272 |
-
# START THE GRADIO SERVER
|
273 |
-
# ------------------------------------------------------------------
|
274 |
demo.queue()
|
275 |
demo.launch(share=True, ssr_mode=False)
|
|
|
215 |
|
216 |
return "✅ Pipeline complete!", image, state, gr.update(interactive=True)
|
217 |
|
218 |
+
# New: run all steps sequentially
|
219 |
+
@spaces.GPU()
|
220 |
+
def run_pipeline(image_array, state):
|
221 |
+
# Step 1: Preprocess
|
222 |
+
status1, crop_img, state, _, _ = preprocess_image(image_array, state)
|
223 |
+
if "❌" in status1:
|
224 |
+
return status1, None, None, None, None, {}
|
225 |
+
# Step 2: Normals
|
226 |
+
status2, normals_img, state, _, _ = step2_normals(state)
|
227 |
+
# Step 3: UV Map
|
228 |
+
status3, uv_img, state, _, _ = step3_uv_map(state)
|
229 |
+
# Step 4: Tracking
|
230 |
+
status4, track_img, state, _ = step4_track(state)
|
231 |
+
final_status = "\n".join([status1, status2, status3, status4])
|
232 |
+
return final_status, crop_img, normals_img, uv_img, track_img, state
|
233 |
+
|
234 |
# Build Gradio UI
|
235 |
demo = gr.Blocks()
|
|
|
236 |
with demo:
|
237 |
+
gr.Markdown("## Image Processing Pipeline (Single Button)")
|
238 |
+
gr.Markdown("Upload an image and click 'Run Pipeline' to execute all steps.")
|
239 |
with gr.Row():
|
240 |
with gr.Column():
|
241 |
image_in = gr.Image(label="Upload Image", type="numpy", height=512)
|
242 |
+
status = gr.Textbox(label="Status", lines=4, interactive=True, value="Upload an image to start.")
|
243 |
state = gr.State({})
|
244 |
with gr.Column():
|
245 |
with gr.Row():
|
|
|
248 |
with gr.Row():
|
249 |
uv_img = gr.Image(label="UV Map", height=256)
|
250 |
track_img = gr.Image(label="Tracking", height=256)
|
251 |
+
run_btn = gr.Button("Run Pipeline")
|
252 |
|
253 |
+
# Single button click
|
254 |
+
run_btn.click(
|
255 |
+
fn=run_pipeline,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
256 |
inputs=[image_in, state],
|
257 |
+
outputs=[status, crop_img, normals_img, uv_img, track_img, state]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
258 |
)
|
259 |
|
260 |
+
image_in.upload(fn=reset_all, inputs=None, outputs=[crop_img, normals_img, uv_img, track_img, status, state])
|
|
|
261 |
|
|
|
|
|
|
|
262 |
demo.queue()
|
263 |
demo.launch(share=True, ssr_mode=False)
|