Kaushik066 commited on
Commit
42e6100
·
1 Parent(s): e398825

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -10
app.py CHANGED
@@ -236,12 +236,22 @@ def prod_function(model_pretrained, prod_ds):
236
  return prod_pred
237
 
238
  # Function to get landmarked video
239
- def tensor_to_video(video_tensor, fps=30):
240
  video_numpy = video_tensor.permute(0, 2, 3, 1).cpu().numpy()
241
  # Normalize values to [0, 255] if necessary
242
  if video_numpy.max() <= 1.0:
243
- video_numpy = (video_numpy * 255).astype(np.uint8)
244
- return video_numpy
 
 
 
 
 
 
 
 
 
 
245
 
246
  # Function to list available videos dynamically
247
  def list_videos():
@@ -257,7 +267,7 @@ def play_video(selected_video):
257
  def translate_sign_language(gesture):
258
  # Create Dataset
259
  prod_ds = dataset_prod_obj.create_dataset(gesture)
260
- prod_video = tensor_to_video(prod_ds)
261
  #prod_video = np.random.randint(0, 255, (32, 225, 225, 3), dtype=np.uint8)
262
 
263
  # Run ML Model
@@ -270,11 +280,11 @@ def translate_sign_language(gesture):
270
  gesture_translation = idx_to_label[predicted_prod_label.cpu().numpy().item()] # Convert to a scalar
271
 
272
  # Frame generator for real-time streaming
273
- def frame_generator():
274
- for frame in prod_video:
275
- yield frame # Stream frame-by-frame
276
 
277
- return gesture_translation , frame_generator() #prod_video
278
 
279
  with gr.Blocks() as demo:
280
  gr.Markdown("# Indian Sign Language Translation App")
@@ -284,10 +294,10 @@ with gr.Blocks() as demo:
284
  with gr.Row(height=350, variant="panel"): # equal_height=False, show_progress=True
285
  with gr.Column(scale=1, variant="panel"):
286
  # Add webcam input for sign language video capture
287
- video_input = gr.Video(format="mp4", label="Gesture")
288
  with gr.Column(scale=1, variant="panel"):
289
  # Display the landmarked video
290
- video_output = gr.Video(streaming=True, label="Landmarked Gesture")
291
  with gr.Row(variant="panel"): # equal_height=False, show_progress=True
292
  with gr.Column(scale=1, variant="panel"):
293
  # Submit the Video
 
236
  return prod_pred
237
 
238
  # Function to get landmarked video
239
+ def tensor_to_video(video_tensor, fps=30, output_path="output.mp4"):
240
  video_numpy = video_tensor.permute(0, 2, 3, 1).cpu().numpy()
241
  # Normalize values to [0, 255] if necessary
242
  if video_numpy.max() <= 1.0:
243
+ video_numpy = (video_numpy * 255).astype(np.uint8)
244
+
245
+ width = video_numpy.shape[2]
246
+ height = video_numpy.shape[3]
247
+ fourcc = cv2.VideoWriter_fourcc(*"mp4v") # MP4 Codec
248
+ out = cv2.VideoWriter(output_path, fourcc, fps, (width, height))
249
+
250
+ for frame in prod_video:
251
+ out.write(frame)
252
+ out.release()
253
+
254
+ return output_path
255
 
256
  # Function to list available videos dynamically
257
  def list_videos():
 
267
  def translate_sign_language(gesture):
268
  # Create Dataset
269
  prod_ds = dataset_prod_obj.create_dataset(gesture)
270
+ prod_video_path = tensor_to_video(prod_ds)
271
  #prod_video = np.random.randint(0, 255, (32, 225, 225, 3), dtype=np.uint8)
272
 
273
  # Run ML Model
 
280
  gesture_translation = idx_to_label[predicted_prod_label.cpu().numpy().item()] # Convert to a scalar
281
 
282
  # Frame generator for real-time streaming
283
+ #def frame_generator():
284
+ # for frame in prod_video:
285
+ # yield frame # Stream frame-by-frame
286
 
287
+ return gesture_translation , prod_video_path # frame_generator
288
 
289
  with gr.Blocks() as demo:
290
  gr.Markdown("# Indian Sign Language Translation App")
 
294
  with gr.Row(height=350, variant="panel"): # equal_height=False, show_progress=True
295
  with gr.Column(scale=1, variant="panel"):
296
  # Add webcam input for sign language video capture
297
+ video_input = gr.Video(sources=["webcam"], format="mp4", label="Gesture")
298
  with gr.Column(scale=1, variant="panel"):
299
  # Display the landmarked video
300
+ video_output = gr.Video(interactive=False, autoplay=True, streaming=False, label="Landmarked Gesture")
301
  with gr.Row(variant="panel"): # equal_height=False, show_progress=True
302
  with gr.Column(scale=1, variant="panel"):
303
  # Submit the Video