Commit ·
b1385df
1
Parent(s): e28ca38
Fix Gradio 6 video input handling
Browse files- app.py +0 -1
- signspeak/pipeline.py +8 -2
- tests/test_asl_pipeline.py +9 -1
app.py
CHANGED
|
@@ -49,7 +49,6 @@ def build_video_input(label: str) -> gr.Video:
|
|
| 49 |
return gr.Video(
|
| 50 |
label=label,
|
| 51 |
sources=["upload", "webcam"],
|
| 52 |
-
type="filepath",
|
| 53 |
format="mp4",
|
| 54 |
)
|
| 55 |
|
|
|
|
| 49 |
return gr.Video(
|
| 50 |
label=label,
|
| 51 |
sources=["upload", "webcam"],
|
|
|
|
| 52 |
format="mp4",
|
| 53 |
)
|
| 54 |
|
signspeak/pipeline.py
CHANGED
|
@@ -28,15 +28,21 @@ def json_text(data: dict[str, Any]) -> str:
|
|
| 28 |
return json.dumps(data, ensure_ascii=False, indent=2)
|
| 29 |
|
| 30 |
|
| 31 |
-
def run_asl_video(video_file:
|
| 32 |
video_path = resolve_video_path(video_file)
|
| 33 |
result = process_asl_video(video_path)
|
| 34 |
intent = result["intent_input"]
|
| 35 |
return json_text(intent), result, summarize_asl_result(result)
|
| 36 |
|
| 37 |
|
| 38 |
-
def resolve_video_path(video_file:
|
| 39 |
if video_file:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
return Path(video_file)
|
| 41 |
if DEFAULT_VIDEO_PATH.exists():
|
| 42 |
return DEFAULT_VIDEO_PATH
|
|
|
|
| 28 |
return json.dumps(data, ensure_ascii=False, indent=2)
|
| 29 |
|
| 30 |
|
| 31 |
+
def run_asl_video(video_file: Any | None) -> tuple[str, dict[str, Any], str]:
|
| 32 |
video_path = resolve_video_path(video_file)
|
| 33 |
result = process_asl_video(video_path)
|
| 34 |
intent = result["intent_input"]
|
| 35 |
return json_text(intent), result, summarize_asl_result(result)
|
| 36 |
|
| 37 |
|
| 38 |
+
def resolve_video_path(video_file: Any | None) -> Path:
|
| 39 |
if video_file:
|
| 40 |
+
if isinstance(video_file, dict):
|
| 41 |
+
video_file = video_file.get("path") or video_file.get("name") or video_file.get("video")
|
| 42 |
+
elif hasattr(video_file, "path"):
|
| 43 |
+
video_file = video_file.path
|
| 44 |
+
elif hasattr(video_file, "name"):
|
| 45 |
+
video_file = video_file.name
|
| 46 |
return Path(video_file)
|
| 47 |
if DEFAULT_VIDEO_PATH.exists():
|
| 48 |
return DEFAULT_VIDEO_PATH
|
tests/test_asl_pipeline.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
from signspeak.asl.pipeline import build_intent_input
|
| 2 |
-
from signspeak.pipeline import summarize_asl_result
|
| 3 |
|
| 4 |
|
| 5 |
def test_build_intent_input_matches_llm_schema():
|
|
@@ -36,3 +36,11 @@ def test_summarize_asl_result_is_stable_for_missing_fields():
|
|
| 36 |
assert "ASL status: model_missing" in summary
|
| 37 |
assert "Emotion: unknown (0.00)" in summary
|
| 38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from signspeak.asl.pipeline import build_intent_input
|
| 2 |
+
from signspeak.pipeline import resolve_video_path, summarize_asl_result
|
| 3 |
|
| 4 |
|
| 5 |
def test_build_intent_input_matches_llm_schema():
|
|
|
|
| 36 |
assert "ASL status: model_missing" in summary
|
| 37 |
assert "Emotion: unknown (0.00)" in summary
|
| 38 |
|
| 39 |
+
|
| 40 |
+
def test_resolve_video_path_accepts_gradio_dict_payload(tmp_path):
|
| 41 |
+
video_path = tmp_path / "capture.mp4"
|
| 42 |
+
video_path.write_bytes(b"demo")
|
| 43 |
+
|
| 44 |
+
resolved = resolve_video_path({"path": str(video_path)})
|
| 45 |
+
|
| 46 |
+
assert resolved == video_path
|