Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -4,73 +4,30 @@ import os
|
|
4 |
|
5 |
BACKEND_URL = os.environ.get("BACKEND_URL", "").strip()
|
6 |
|
7 |
-
|
8 |
-
"""Forward request to backend"""
|
9 |
try:
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
conf_thresh,
|
16 |
-
max_dets,
|
17 |
-
task_type,
|
18 |
-
api_name="/predict"
|
19 |
)
|
20 |
-
|
|
|
21 |
except Exception as e:
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
with gr.Column(scale=1):
|
29 |
-
with gr.Tabs():
|
30 |
-
with gr.TabItem("Upload File"):
|
31 |
-
input_file = gr.File(label="Upload Image or Video", file_types=["image", "video"])
|
32 |
-
display_raw_image_file = gr.Image(visible=False)
|
33 |
-
display_raw_video_file = gr.Video(visible=False)
|
34 |
-
|
35 |
-
with gr.TabItem("Webcam"):
|
36 |
-
gr.Markdown("Click on feed or press Enter to capture")
|
37 |
-
input_webcam = gr.Image(sources=["webcam"], type="pil")
|
38 |
-
display_raw_image_webcam = gr.Image(visible=False)
|
39 |
-
|
40 |
-
clear_button = gr.Button("Clear All Inputs & Outputs")
|
41 |
-
|
42 |
-
with gr.Column(scale=1):
|
43 |
-
gr.Markdown("### Processed Output")
|
44 |
-
display_processed_image = gr.Image(visible=False)
|
45 |
-
display_processed_video = gr.Video(visible=False)
|
46 |
-
|
47 |
-
submit_button = gr.Button("Detect Faces", variant="primary")
|
48 |
-
|
49 |
-
with gr.Column():
|
50 |
-
gr.Markdown("### Detection Controls")
|
51 |
-
model_choice = gr.Radio(["MMDetection"], value="MMDetection", visible=False)
|
52 |
-
task_type = gr.Dropdown(
|
53 |
-
["Face Detection", "Face Pose Estimation", "Gaze Estimation [experimental]"],
|
54 |
-
value="Face Detection",
|
55 |
-
label="Select Task"
|
56 |
)
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
submit_button.click(
|
65 |
-
process_with_backend,
|
66 |
-
inputs=[input_file, input_webcam, model_choice, conf_threshold, max_detections, task_type],
|
67 |
-
outputs=outputs
|
68 |
-
)
|
69 |
-
|
70 |
-
# Simplified clear function
|
71 |
-
clear_button.click(
|
72 |
-
lambda: [gr.update(value=None) for _ in range(5)],
|
73 |
-
outputs=outputs
|
74 |
)
|
75 |
|
76 |
demo.launch()
|
|
|
4 |
|
5 |
BACKEND_URL = os.environ.get("BACKEND_URL", "").strip()
|
6 |
|
7 |
+
if BACKEND_URL:
|
|
|
8 |
try:
|
9 |
+
# Load the entire interface from backend
|
10 |
+
demo = gr.Interface.load(
|
11 |
+
name=BACKEND_URL,
|
12 |
+
title="PrimateFace Detection, Pose & Gaze Demo",
|
13 |
+
description="Connected to GPU backend server"
|
|
|
|
|
|
|
|
|
14 |
)
|
15 |
+
# Add header to bypass ngrok warning
|
16 |
+
demo.headers = {"ngrok-skip-browser-warning": "true"}
|
17 |
except Exception as e:
|
18 |
+
# Fallback if backend is down
|
19 |
+
demo = gr.Interface(
|
20 |
+
fn=lambda x: "GPU server is offline. Please try again later.",
|
21 |
+
inputs=gr.Textbox(),
|
22 |
+
outputs=gr.Textbox(),
|
23 |
+
title="PrimateFace Demo - Offline"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
)
|
25 |
+
else:
|
26 |
+
demo = gr.Interface(
|
27 |
+
fn=lambda x: "Backend URL not configured in Space settings.",
|
28 |
+
inputs=gr.Textbox(),
|
29 |
+
outputs=gr.Textbox(),
|
30 |
+
title="PrimateFace Demo - Not Configured"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
)
|
32 |
|
33 |
demo.launch()
|