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