jaimin commited on
Commit
e8c1ba3
1 Parent(s): 7ab43a9

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from concurrent.futures import ThreadPoolExecutor
3
+ import gradio as gr
4
+ from bpm_app.heartBPM_modified_copy import heart
5
+ from stress_detection.eyebrow_detection_modified_copy import stress
6
+
7
+ def process_heart_stress(video_file):
8
+ # Validate the input file path
9
+ if not video_file or not os.path.isfile(video_file):
10
+ return {'error': 'Invalid video path'}
11
+
12
+ # Run heart rate and stress detection functions in parallel
13
+ with ThreadPoolExecutor() as executor:
14
+ heart_future = executor.submit(heart, video_file)
15
+ stress_future = executor.submit(stress, video_file, duration=30)
16
+
17
+ # Retrieve results
18
+ avg_bpm, frames_processed = heart_future.result()
19
+ stressed_count, not_stressed_count, most_frequent_label = stress_future.result()
20
+
21
+ # Compile results
22
+ results = {
23
+ 'Average BPM': avg_bpm,
24
+ 'Most Frequent Stress State': most_frequent_label,
25
+ }
26
+
27
+ return results
28
+
29
+ # Define Gradio interface for Heart and Stress Measurement
30
+ gr.Interface(
31
+ fn=process_heart_stress,
32
+ inputs=gr.Video(label="Upload a video file"),
33
+ outputs="json",
34
+ title="Heart Rate and Stress Measurement"
35
+ ).launch(server_name="0.0.0.0")