File size: 1,096 Bytes
efabbbd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import cv2
import numpy as np

def analyze_skin_conductance(image):
    img = image if isinstance(image, np.ndarray) else cv2.imread(image)
    if img is None:
        return "Error: Unable to process the image."
    
    hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
    mask = cv2.inRange(hsv, np.array([0, 20, 70], dtype=np.uint8), np.array([20, 150, 255], dtype=np.uint8))
    
    sweat_percentage = (np.count_nonzero(mask) / mask.size) * 100
    stress_level = "Low" if sweat_percentage < 10 else "Medium" if sweat_percentage < 30 else "High"
    
    return f"Estimated stress/arousal level: {stress_level}\nSweat indicator percentage: {sweat_percentage:.2f}%"

def create_skin_conductance_tab():
    with gr.Column():
        image_input = gr.Image()
        analyze_button = gr.Button("Analyze")
        output = gr.Textbox(label="Analysis Results")
        
        analyze_button.click(analyze_skin_conductance, inputs=image_input, outputs=output)
        
        # Add the Examples component
        gr.Examples(["./assets/images/fitness.jpg"], inputs=[image_input])