File size: 2,536 Bytes
cba0a6a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import os
import gradio as gr
from modules.eeg_processor import EEGProcessor
from modules.brain_mapper import BrainMapper
from modules.clinical_analyzer import ClinicalAnalyzer
from modules.treatment_planner import TreatmentPlanner

def process_eeg(file_obj):
    processor = EEGProcessor()
    mapper = BrainMapper()
    analyzer = ClinicalAnalyzer()
    planner = TreatmentPlanner()
    
    # Process EEG data
    eeg_data = processor.process_file(file_obj.name)
    
    # Generate visualizations
    brain_map = mapper.generate_topographic_map(eeg_data)
    connectivity = mapper.generate_connectivity_map(eeg_data)
    
    # Perform analysis
    clinical_analysis = analyzer.analyze_eeg(eeg_data)
    mental_health_assessment = analyzer.assess_mental_health(clinical_analysis)
    risk_factors = analyzer.identify_risk_factors(clinical_analysis)
    
    # Generate treatment plan
    treatment_plan = planner.generate_plan(clinical_analysis, mental_health_assessment)
    
    return {
        "Brain Activity Map": brain_map,
        "Brain Connectivity": connectivity,
        "Clinical Analysis": clinical_analysis,
        "Mental Health Assessment": mental_health_assessment,
        "Risk Factors": risk_factors,
        "Treatment Recommendations": treatment_plan
    }

# Create Gradio interface
with gr.Blocks(title="AI-Powered Mental Health Analysis Platform") as demo:
    gr.Markdown("# AI-Powered Mental Health Analysis Platform")
    gr.Markdown("Upload your EEG data file for analysis and treatment recommendations.")
    
    with gr.Row():
        with gr.Column():
            file_input = gr.File(label="Upload EEG Data (EDF, BDF, or CNT format)")
            analyze_btn = gr.Button("Analyze")
        
        with gr.Column():
            brain_map = gr.Plot(label="Brain Activity Map")
            connectivity_map = gr.Plot(label="Brain Connectivity")
            
    with gr.Row():
        with gr.Column():
            clinical_output = gr.JSON(label="Clinical Analysis")
            assessment_output = gr.JSON(label="Mental Health Assessment")
        
        with gr.Column():
            risk_output = gr.JSON(label="Risk Factors")
            treatment_output = gr.Markdown(label="Treatment Recommendations")
    
    analyze_btn.click(
        fn=process_eeg,
        inputs=[file_input],
        outputs=[brain_map, connectivity_map, clinical_output, 
                assessment_output, risk_output, treatment_output]
    )

# Launch the interface
if __name__ == "__main__":
    demo.launch()