Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -40,27 +40,40 @@ def analyze_voice(audio_file):
|
|
40 |
with torch.no_grad():
|
41 |
outputs = model(**inputs)
|
42 |
|
43 |
-
# Extract features
|
44 |
features = outputs.last_hidden_state.mean(dim=1).numpy()
|
45 |
|
46 |
-
#
|
47 |
-
respiratory_score = np.mean(features)
|
48 |
-
mental_health_score = np.std(features)
|
|
|
|
|
|
|
|
|
|
|
49 |
feedback = ""
|
50 |
-
if respiratory_score > 0.1:
|
51 |
-
feedback += "Possible respiratory issue detected; consult a doctor. "
|
52 |
-
if mental_health_score > 0.1:
|
53 |
-
feedback += "Possible stress indicators detected; consider professional advice. "
|
54 |
|
55 |
if not feedback:
|
56 |
feedback = "No significant health indicators detected."
|
57 |
|
58 |
-
feedback += "\n\n**
|
|
|
59 |
|
60 |
# Store in Salesforce
|
61 |
if sf:
|
62 |
store_in_salesforce(audio_file, feedback, respiratory_score, mental_health_score)
|
63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
return feedback
|
65 |
except Exception as e:
|
66 |
return f"Error processing audio: {str(e)}"
|
@@ -80,7 +93,7 @@ def store_in_salesforce(audio_file, feedback, respiratory_score, mental_health_s
|
|
80 |
|
81 |
def test_with_sample_audio():
|
82 |
"""Test the app with a sample audio file."""
|
83 |
-
sample_audio_path = "audio_samples/sample.wav" #
|
84 |
if os.path.exists(sample_audio_path):
|
85 |
return analyze_voice(sample_audio_path)
|
86 |
return "Sample audio file not found."
|
|
|
40 |
with torch.no_grad():
|
41 |
outputs = model(**inputs)
|
42 |
|
43 |
+
# Extract features
|
44 |
features = outputs.last_hidden_state.mean(dim=1).numpy()
|
45 |
|
46 |
+
# Mock health analysis (for testing)
|
47 |
+
respiratory_score = np.mean(features)
|
48 |
+
mental_health_score = np.std(features)
|
49 |
+
|
50 |
+
# Debug: Print scores
|
51 |
+
print(f"Respiratory Score: {respiratory_score:.4f}, Mental Health Score: {mental_health_score:.4f}")
|
52 |
+
|
53 |
+
# Adjusted thresholds for testing
|
54 |
feedback = ""
|
55 |
+
if respiratory_score > 0.1:
|
56 |
+
feedback += f"Possible respiratory issue detected (score: {respiratory_score:.4f}); consult a doctor. "
|
57 |
+
if mental_health_score > 0.1:
|
58 |
+
feedback += f"Possible stress indicators detected (score: {mental_health_score:.4f}); consider professional advice. "
|
59 |
|
60 |
if not feedback:
|
61 |
feedback = "No significant health indicators detected."
|
62 |
|
63 |
+
feedback += f"\n\n**Debug Info**: Respiratory Score = {respiratory_score:.4f}, Mental Health Score = {mental_health_score:.4f}"
|
64 |
+
feedback += "\n**Disclaimer**: This is not a diagnostic tool. Consult a healthcare provider for medical advice."
|
65 |
|
66 |
# Store in Salesforce
|
67 |
if sf:
|
68 |
store_in_salesforce(audio_file, feedback, respiratory_score, mental_health_score)
|
69 |
|
70 |
+
# Clean up temporary audio file (for HIPAA/GDPR compliance)
|
71 |
+
try:
|
72 |
+
os.remove(audio_file)
|
73 |
+
print(f"Deleted temporary audio file: {audio_file}")
|
74 |
+
except Exception as e:
|
75 |
+
print(f"Failed to delete audio file: {str(e)}")
|
76 |
+
|
77 |
return feedback
|
78 |
except Exception as e:
|
79 |
return f"Error processing audio: {str(e)}"
|
|
|
93 |
|
94 |
def test_with_sample_audio():
|
95 |
"""Test the app with a sample audio file."""
|
96 |
+
sample_audio_path = "audio_samples/sample.wav" # Adjust if using common_voice_sample.wav
|
97 |
if os.path.exists(sample_audio_path):
|
98 |
return analyze_voice(sample_audio_path)
|
99 |
return "Sample audio file not found."
|