File size: 1,863 Bytes
822dda9
46e3bf1
 
822dda9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46e3bf1
 
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
import gradio as gr
from models import ModelManager, AudioProcessor, Analyzer
from utils import visualizer, GPUOptimizer, ModelCache

# Initialize components
optimizer = GPUOptimizer()
optimizer.optimize()

model_manager = ModelManager()
audio_processor = AudioProcessor()
analyzer = Analyzer(model_manager, audio_processor)
cache = ModelCache()

def process_audio(audio_file):
    try:
        # Check cache
        with open(audio_file, 'rb') as f:
            cache_key = cache.get_cache_key(f.read())
        
        cached_result = cache.cache_result(cache_key, None)
        if cached_result:
            return cached_result
        
        # Process audio
        results = analyzer.analyze(audio_file)
        
        # Format outputs
        outputs = (
            results['transcription'],
            visualizer.create_emotion_plot(results['emotions']['scores']),
            _format_indicators(results['mental_health_indicators'])
        )
        
        # Cache results
        cache.cache_result(cache_key, outputs)
        
        return outputs
        
    except Exception as e:
        return str(e), "Error in analysis", "Error in analysis"

def _format_indicators(indicators):
    return f"""
    ### Mental Health Indicators
    - Depression Risk: {indicators['depression_risk']:.2f}
    - Anxiety Risk: {indicators['anxiety_risk']:.2f}
    - Stress Level: {indicators['stress_level']:.2f}
    """

interface = gr.Interface(
    fn=process_audio,
    inputs=gr.Audio(source="microphone", type="filepath"),
    outputs=[
        gr.Textbox(label="Transcription"),
        gr.HTML(label="Emotion Analysis"),
        gr.Markdown(label="Mental Health Indicators")
    ],
    title="Vocal Biomarker Analysis",
    description="Analyze voice for emotional and mental health indicators"
)

if __name__ == "__main__":
    interface.launch()