Spaces:
Sleeping
Sleeping
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -64,6 +64,17 @@ def analyze(image: np.ndarray):
|
|
| 64 |
Entry point called by Gradio.
|
| 65 |
Returns: (annotated_image, gender_html, age_html, emotion_html, aged_image)
|
| 66 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
if image is None:
|
| 68 |
empty = _blank("No image received")
|
| 69 |
return empty, "–", "–", "–", empty
|
|
@@ -388,9 +399,9 @@ def build_app() -> gr.Blocks:
|
|
| 388 |
outputs = [annotated_out, gender_out, age_out, emotion_out, aged_out],
|
| 389 |
)
|
| 390 |
|
| 391 |
-
#
|
| 392 |
image_input.change(
|
| 393 |
-
fn = analyze,
|
| 394 |
inputs = [image_input],
|
| 395 |
outputs = [annotated_out, gender_out, age_out, emotion_out, aged_out],
|
| 396 |
)
|
|
|
|
| 64 |
Entry point called by Gradio.
|
| 65 |
Returns: (annotated_image, gender_html, age_html, emotion_html, aged_image)
|
| 66 |
"""
|
| 67 |
+
try:
|
| 68 |
+
return _analyze_inner(image)
|
| 69 |
+
except Exception as exc:
|
| 70 |
+
import traceback
|
| 71 |
+
traceback.print_exc()
|
| 72 |
+
err = _card(f"Error: {exc}", "Check Space logs for details")
|
| 73 |
+
blank = _blank("Error")
|
| 74 |
+
return blank, err, err, err, blank
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
def _analyze_inner(image: np.ndarray):
|
| 78 |
if image is None:
|
| 79 |
empty = _blank("No image received")
|
| 80 |
return empty, "–", "–", "–", empty
|
|
|
|
| 399 |
outputs = [annotated_out, gender_out, age_out, emotion_out, aged_out],
|
| 400 |
)
|
| 401 |
|
| 402 |
+
# Run on webcam changes only when image is not None
|
| 403 |
image_input.change(
|
| 404 |
+
fn = lambda img: analyze(img) if img is not None else (None,)*5,
|
| 405 |
inputs = [image_input],
|
| 406 |
outputs = [annotated_out, gender_out, age_out, emotion_out, aged_out],
|
| 407 |
)
|