Spaces:
Sleeping
Sleeping
fix streaming + license + analysis
Browse files
app.py
CHANGED
|
@@ -96,10 +96,21 @@ def draw_confidence_bar(frame, conf, x, y, width=240, height=24):
|
|
| 96 |
def predict(frame):
|
| 97 |
if frame is None:
|
| 98 |
return None
|
| 99 |
-
frame = np.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
h, w = frame.shape[:2]
|
| 101 |
-
|
| 102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
|
| 104 |
if not result.hand_landmarks:
|
| 105 |
HISTORY.clear()
|
|
@@ -123,20 +134,24 @@ def predict(frame):
|
|
| 123 |
return frame
|
| 124 |
|
| 125 |
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
fn=predict,
|
| 132 |
-
inputs=gr.Image(sources=["webcam"], streaming=True, label="Webcam"),
|
| 133 |
-
outputs=gr.Image(label="Prediction"),
|
| 134 |
-
live=True,
|
| 135 |
-
title="ASL Hand Gesture Recognizer",
|
| 136 |
-
description="ASL hand gesture recognizer (A–Z, 0–9). Dataset: ASL-HG by Pranto et al. (2026) — https://www.sciencedirect.com/science/article/pii/S2352340926000454 | Model by Doruk Doğular",
|
| 137 |
-
**_flag_kw,
|
| 138 |
)
|
| 139 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
|
| 141 |
if __name__ == "__main__":
|
| 142 |
demo.launch()
|
|
|
|
| 96 |
def predict(frame):
|
| 97 |
if frame is None:
|
| 98 |
return None
|
| 99 |
+
frame = np.asarray(frame)
|
| 100 |
+
if frame.ndim == 2:
|
| 101 |
+
frame = cv2.cvtColor(frame, cv2.COLOR_GRAY2RGB)
|
| 102 |
+
if frame.shape[2] == 4:
|
| 103 |
+
frame = frame[:, :, :3]
|
| 104 |
+
frame = np.ascontiguousarray(frame, dtype=np.uint8)
|
| 105 |
h, w = frame.shape[:2]
|
| 106 |
+
|
| 107 |
+
try:
|
| 108 |
+
mp_image = MP.Image(image_format=MP.ImageFormat.SRGB, data=frame)
|
| 109 |
+
result = LANDMARKER.detect(mp_image)
|
| 110 |
+
except Exception as exc:
|
| 111 |
+
cv2.putText(frame, f"err: {type(exc).__name__}", (20, 44),
|
| 112 |
+
cv2.FONT_HERSHEY_SIMPLEX, 0.9, (255, 80, 80), 2)
|
| 113 |
+
return frame
|
| 114 |
|
| 115 |
if not result.hand_landmarks:
|
| 116 |
HISTORY.clear()
|
|
|
|
| 134 |
return frame
|
| 135 |
|
| 136 |
|
| 137 |
+
DESCRIPTION = (
|
| 138 |
+
"Show an ASL letter (A–Z) or digit (0–9) to your webcam and hold steady. "
|
| 139 |
+
"Dataset: ASL-HG by Pranto et al. (2026) — "
|
| 140 |
+
"https://www.sciencedirect.com/science/article/pii/S2352340926000454 | "
|
| 141 |
+
"Model by Doruk Doğular (nocontextdoruk)."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
)
|
| 143 |
|
| 144 |
+
with gr.Blocks(title="ASL Hand Gesture Recognizer") as demo:
|
| 145 |
+
gr.Markdown("# ASL Hand Gesture Recognizer")
|
| 146 |
+
gr.Markdown(DESCRIPTION)
|
| 147 |
+
with gr.Row():
|
| 148 |
+
webcam = gr.Image(sources=["webcam"], streaming=True, type="numpy", label="Webcam")
|
| 149 |
+
output = gr.Image(label="Prediction", type="numpy")
|
| 150 |
+
webcam.stream(predict, inputs=webcam, outputs=output,
|
| 151 |
+
stream_every=0.15, concurrency_limit=30)
|
| 152 |
+
|
| 153 |
+
demo.queue()
|
| 154 |
+
|
| 155 |
|
| 156 |
if __name__ == "__main__":
|
| 157 |
demo.launch()
|