aziraarshad commited on
Commit
0fadbc5
·
verified ·
1 Parent(s): e9e9f89

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -27
app.py CHANGED
@@ -253,33 +253,24 @@ def run(frame, sequence_state):
253
 
254
  return out_rgb, probs_dict, sequence_state
255
 
256
- # Legacy Gradio-compatible state
257
- sequence_state = []
258
-
259
- def predict(frame):
260
- global sequence_state
261
-
262
- if frame is None:
263
- return None, {"(no frame)": 1.0}
264
-
265
- # Sometimes legacy Gradio provides PIL
266
- if isinstance(frame, Image.Image):
267
- frame = np.array(frame)
268
-
269
- out_img, probs_dict, sequence_state = run(frame, sequence_state)
270
- return out_img, probs_dict
271
-
272
- demo = gr.Interface(
273
- fn=predict,
274
- inputs=gr.inputs.Image(source="webcam", type="numpy", label="Webcam"),
275
- outputs=[
276
- gr.outputs.Image(type="numpy", label="Output (Annotated)"),
277
- gr.outputs.Label(num_top_classes=5, label="Probabilities (Top 5)"),
278
- ],
279
- title="Live Sign Language Gesture Demo (CNN-LSTM + Multi-Head Attention)",
280
- description="Show your hand gesture to the webcam. Prediction starts after 30 frames are collected.",
281
- live=True,
282
- )
283
 
284
  if __name__ == "__main__":
285
  demo.launch()
 
253
 
254
  return out_rgb, probs_dict, sequence_state
255
 
256
+ with gr.Blocks() as demo:
257
+ gr.Markdown("# Live Sign Language Gesture Demo (CNN-LSTM + Multi-Head Attention)")
258
+ gr.Markdown("Show your hand gesture to the webcam. Prediction starts after 30 frames are collected.")
259
+
260
+ seq_state = gr.State([])
261
+
262
+ with gr.Row():
263
+ cam = gr.Image(sources=["webcam"], type="numpy", label="Webcam")
264
+ out_img = gr.Image(type="numpy", label="Output (Annotated)")
265
+
266
+ out_label = gr.Label(num_top_classes=5, label="Probabilities (Top 5)")
267
+
268
+ # Stream events are supported in gradio 4.x
269
+ cam.stream(
270
+ fn=run,
271
+ inputs=[cam, seq_state],
272
+ outputs=[out_img, out_label, seq_state],
273
+ )
 
 
 
 
 
 
 
 
 
274
 
275
  if __name__ == "__main__":
276
  demo.launch()