Update app.py
Browse files
app.py
CHANGED
@@ -3,14 +3,27 @@ import librosa
|
|
3 |
import numpy as np
|
4 |
import torch
|
5 |
from transformers import Wav2Vec2Processor, Wav2Vec2Model
|
6 |
-
import
|
7 |
-
import json
|
8 |
import os
|
9 |
from datetime import datetime
|
10 |
|
11 |
-
# Salesforce
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
# Load Wav2Vec2 model for speech feature extraction
|
16 |
processor = Wav2Vec2Processor.from_pretrained("facebook/wav2vec2-base-960h")
|
@@ -45,7 +58,8 @@ def analyze_voice(audio_file):
|
|
45 |
feedback += "\n\n**Disclaimer**: This is not a diagnostic tool. Consult a healthcare provider for medical advice."
|
46 |
|
47 |
# Store in Salesforce
|
48 |
-
|
|
|
49 |
|
50 |
return feedback
|
51 |
except Exception as e:
|
@@ -53,20 +67,16 @@ def analyze_voice(audio_file):
|
|
53 |
|
54 |
def store_in_salesforce(audio_file, feedback, respiratory_score, mental_health_score):
|
55 |
"""Store analysis results in Salesforce."""
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
"
|
66 |
-
}
|
67 |
-
response = requests.post(SALESFORCE_API_URL, headers=headers, json=data)
|
68 |
-
if response.status_code != 201:
|
69 |
-
print(f"Failed to store in Salesforce: {response.text}")
|
70 |
|
71 |
# Gradio interface
|
72 |
iface = gr.Interface(
|
|
|
3 |
import numpy as np
|
4 |
import torch
|
5 |
from transformers import Wav2Vec2Processor, Wav2Vec2Model
|
6 |
+
from simple_salesforce import Salesforce
|
|
|
7 |
import os
|
8 |
from datetime import datetime
|
9 |
|
10 |
+
# Salesforce credentials (store securely in environment variables)
|
11 |
+
SF_USERNAME = os.getenv("SF_USERNAME", "smartvoicebot@voice.com")
|
12 |
+
SF_PASSWORD = os.getenv("SF_PASSWORD", "voicebot1")
|
13 |
+
SF_SECURITY_TOKEN = os.getenv("SF_SECURITY_TOKEN", "jq4VVHUFti6TmzJDjjegv2h6b")
|
14 |
+
SF_INSTANCE_URL = os.getenv("SF_INSTANCE_URL", "https://voicebot-dev-ed.develop.lightning.force.com/lightning/setup/SetupOneHome/home")
|
15 |
+
|
16 |
+
# Initialize Salesforce connection
|
17 |
+
try:
|
18 |
+
sf = Salesforce(
|
19 |
+
username=SF_USERNAME,
|
20 |
+
password=SF_PASSWORD,
|
21 |
+
security_token=SF_SECURITY_TOKEN,
|
22 |
+
instance_url=SF_INSTANCE_URL
|
23 |
+
)
|
24 |
+
except Exception as e:
|
25 |
+
print(f"Failed to connect to Salesforce: {str(e)}")
|
26 |
+
sf = None
|
27 |
|
28 |
# Load Wav2Vec2 model for speech feature extraction
|
29 |
processor = Wav2Vec2Processor.from_pretrained("facebook/wav2vec2-base-960h")
|
|
|
58 |
feedback += "\n\n**Disclaimer**: This is not a diagnostic tool. Consult a healthcare provider for medical advice."
|
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:
|
|
|
67 |
|
68 |
def store_in_salesforce(audio_file, feedback, respiratory_score, mental_health_score):
|
69 |
"""Store analysis results in Salesforce."""
|
70 |
+
try:
|
71 |
+
sf.HealthAssessment__c.create({
|
72 |
+
"AssessmentDate__c": datetime.utcnow().isoformat(),
|
73 |
+
"Feedback__c": feedback,
|
74 |
+
"RespiratoryScore__c": float(respiratory_score),
|
75 |
+
"MentalHealthScore__c": float(mental_health_score),
|
76 |
+
"AudioFileName__c": os.path.basename(audio_file)
|
77 |
+
})
|
78 |
+
except Exception as e:
|
79 |
+
print(f"Failed to store in Salesforce: {str(e)}")
|
|
|
|
|
|
|
|
|
80 |
|
81 |
# Gradio interface
|
82 |
iface = gr.Interface(
|