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")