AI-RESEARCHER-2024 commited on
Commit
19fb2ff
Β·
verified Β·
1 Parent(s): d270c5d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -13
app.py CHANGED
@@ -1,9 +1,10 @@
1
  import spaces
2
 
3
- # Add this dummy function (not recommended)
4
- @spaces.GPU
5
- def dummy_gpu_function():
6
- pass
 
7
 
8
  import gradio as gr
9
  from google import genai
@@ -452,8 +453,31 @@ def get_video_info(video_path):
452
  except:
453
  return None, None, None, None
454
 
455
- # Define the processing function
456
- def process_video(video, resize_option):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
457
  """Process uploaded or recorded video"""
458
 
459
  if video is None:
@@ -589,6 +613,11 @@ def process_video(video, resize_option):
589
  print(error_msg)
590
  return error_msg, None, None, None
591
 
 
 
 
 
 
592
  # Create and launch the Gradio interface
593
  print("πŸš€ Launching CICE 2.0 Healthcare Assessment Tool...")
594
 
@@ -631,19 +660,27 @@ with gr.Blocks(title="CICE 2.0 Healthcare Assessment Tool", theme=gr.themes.Soft
631
  format="mp4",
632
  include_audio=True,
633
  interactive=True,
634
- webcam_constraints={"video": {"width": 800, "height": 600}}
 
 
635
  )
636
 
637
- analyze_btn = gr.Button("πŸ” Analyze Video", variant="primary", size="lg")
 
 
 
 
 
638
 
639
  gr.Markdown("""
640
  ### πŸ“ Instructions:
641
  1. **Select video resolution** (lower = faster processing)
642
  2. **Upload** a pre-recorded video or **Record** using your webcam
643
- 3. Click **Analyze Video** to start the assessment
644
- 4. Wait for the AI to process (1-2 minutes)
645
- 5. Listen to the **1-minute audio summary**
646
- 6. Download the **PDF report** for documentation
 
647
 
648
  **Video Resolution Guide:**
649
  - **640x480**: Fastest processing, uses least quota
@@ -663,6 +700,9 @@ with gr.Blocks(title="CICE 2.0 Healthcare Assessment Tool", theme=gr.themes.Soft
663
  with gr.Column(scale=2):
664
  gr.Markdown("### πŸ“Š Assessment Results")
665
 
 
 
 
666
  # Visual summary
667
  summary_output = gr.HTML(
668
  label="Visual Summary",
@@ -707,9 +747,21 @@ with gr.Blocks(title="CICE 2.0 Healthcare Assessment Tool", theme=gr.themes.Soft
707
  - πŸ“Š 1-minute audio summary (MP3 format)
708
  - πŸ“„ Complete PDF assessment report
709
 
710
- **Powered by Google Gemini 2.0 Flash**
711
  """)
712
 
 
 
 
 
 
 
 
 
 
 
 
 
713
  # Connect the analyze button
714
  analyze_btn.click(
715
  fn=process_video,
 
1
  import spaces
2
 
3
+ # Configure GPU L405
4
+ @spaces.GPU(duration=120)
5
+ def process_video_with_gpu(video, resize_option, assessor):
6
+ """GPU-accelerated video processing"""
7
+ return process_video_core(video, resize_option, assessor)
8
 
9
  import gradio as gr
10
  from google import genai
 
453
  except:
454
  return None, None, None, None
455
 
456
+ # Function to save video immediately after recording
457
+ def save_recorded_video(video):
458
+ """Save the recorded video and make it downloadable"""
459
+ if video is None:
460
+ return None
461
+
462
+ try:
463
+ # Create a copy of the video file with a timestamp
464
+ timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
465
+ output_filename = f"recorded_video_{timestamp}.mp4"
466
+ temp_output = tempfile.NamedTemporaryFile(delete=False, suffix='.mp4', prefix=f"recorded_{timestamp}_")
467
+
468
+ # Copy the video file
469
+ import shutil
470
+ shutil.copy2(video, temp_output.name)
471
+ temp_output.close()
472
+
473
+ print(f"πŸ“Ή Video saved: {output_filename}")
474
+ return temp_output.name
475
+ except Exception as e:
476
+ print(f"⚠️ Failed to save video: {str(e)}")
477
+ return None
478
+
479
+ # Define the core processing function (separate from GPU wrapper)
480
+ def process_video_core(video, resize_option, assessor):
481
  """Process uploaded or recorded video"""
482
 
483
  if video is None:
 
613
  print(error_msg)
614
  return error_msg, None, None, None
615
 
616
+ # Wrapper function that calls the GPU-accelerated version
617
+ def process_video(video, resize_option):
618
+ """Wrapper function to call GPU-accelerated processing"""
619
+ return process_video_with_gpu(video, resize_option, assessor)
620
+
621
  # Create and launch the Gradio interface
622
  print("πŸš€ Launching CICE 2.0 Healthcare Assessment Tool...")
623
 
 
660
  format="mp4",
661
  include_audio=True,
662
  interactive=True,
663
+ webcam_constraints={"video": {"width": 800, "height": 600}},
664
+ autoplay=False, # Disable autoplay for faster loading
665
+ show_download_button=True # Show download button immediately
666
  )
667
 
668
+ # Add download component for recorded videos
669
+ recorded_video_download = gr.File(
670
+ label="πŸ“₯ Download Recorded Video",
671
+ interactive=False,
672
+ visible=False
673
+ )
674
 
675
  gr.Markdown("""
676
  ### πŸ“ Instructions:
677
  1. **Select video resolution** (lower = faster processing)
678
  2. **Upload** a pre-recorded video or **Record** using your webcam
679
+ 3. Video will be saved and downloadable immediately after recording stops
680
+ 4. Click **Analyze Video** (on the right) to start the assessment
681
+ 5. Wait for the AI to process (1-2 minutes)
682
+ 6. Listen to the **1-minute audio summary**
683
+ 7. Download the **PDF report** for documentation
684
 
685
  **Video Resolution Guide:**
686
  - **640x480**: Fastest processing, uses least quota
 
700
  with gr.Column(scale=2):
701
  gr.Markdown("### πŸ“Š Assessment Results")
702
 
703
+ # Move analyze button here (to the right column)
704
+ analyze_btn = gr.Button("πŸ” Analyze Video", variant="primary", size="lg")
705
+
706
  # Visual summary
707
  summary_output = gr.HTML(
708
  label="Visual Summary",
 
747
  - πŸ“Š 1-minute audio summary (MP3 format)
748
  - πŸ“„ Complete PDF assessment report
749
 
750
+ **Powered by Google Gemini 2.0 Flash | GPU-Accelerated with HuggingFace L405**
751
  """)
752
 
753
+ # Auto-save video when recording stops
754
+ video_input.stop_recording(
755
+ fn=save_recorded_video,
756
+ inputs=[video_input],
757
+ outputs=[recorded_video_download],
758
+ api_name="save_video"
759
+ ).then(
760
+ fn=lambda x: gr.update(visible=True if x else False),
761
+ inputs=[recorded_video_download],
762
+ outputs=[recorded_video_download]
763
+ )
764
+
765
  # Connect the analyze button
766
  analyze_btn.click(
767
  fn=process_video,