RathodHarish commited on
Commit
a937006
·
verified ·
1 Parent(s): bf1b93d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -8
app.py CHANGED
@@ -8,10 +8,10 @@ import os
8
  from datetime import datetime
9
 
10
  # Salesforce credentials (store securely in environment variables)
11
- SF_USERNAME = os.getenv("SF_USERNAME", "[email protected]")
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:
@@ -40,16 +40,16 @@ def analyze_voice(audio_file):
40
  with torch.no_grad():
41
  outputs = model(**inputs)
42
 
43
- # Extract features (simplified for demo; real-world needs trained classifier)
44
  features = outputs.last_hidden_state.mean(dim=1).numpy()
45
 
46
- # Placeholder health analysis (replace with trained model)
47
  respiratory_score = np.mean(features) # Mock score
48
  mental_health_score = np.std(features) # Mock score
49
  feedback = ""
50
- if respiratory_score > 0.5:
51
  feedback += "Possible respiratory issue detected; consult a doctor. "
52
- if mental_health_score > 0.3:
53
  feedback += "Possible stress indicators detected; consider professional advice. "
54
 
55
  if not feedback:
@@ -78,6 +78,13 @@ def store_in_salesforce(audio_file, feedback, respiratory_score, mental_health_s
78
  except Exception as e:
79
  print(f"Failed to store in Salesforce: {str(e)}")
80
 
 
 
 
 
 
 
 
81
  # Gradio interface
82
  iface = gr.Interface(
83
  fn=analyze_voice,
@@ -88,4 +95,5 @@ iface = gr.Interface(
88
  )
89
 
90
  if __name__ == "__main__":
 
91
  iface.launch(server_name="0.0.0.0", server_port=7860)
 
8
  from datetime import datetime
9
 
10
  # Salesforce credentials (store securely in environment variables)
11
+ SF_USERNAME = os.getenv("SF_USERNAME", "your_salesforce_username")
12
+ SF_PASSWORD = os.getenv("SF_PASSWORD", "your_salesforce_password")
13
+ SF_SECURITY_TOKEN = os.getenv("SF_SECURITY_TOKEN", "your_salesforce_security_token")
14
+ SF_INSTANCE_URL = os.getenv("SF_INSTANCE_URL", "https://your-salesforce-instance.salesforce.com")
15
 
16
  # Initialize Salesforce connection
17
  try:
 
40
  with torch.no_grad():
41
  outputs = model(**inputs)
42
 
43
+ # Extract features (simplified for demo)
44
  features = outputs.last_hidden_state.mean(dim=1).numpy()
45
 
46
+ # Adjusted thresholds for testing (lower to trigger feedback)
47
  respiratory_score = np.mean(features) # Mock score
48
  mental_health_score = np.std(features) # Mock score
49
  feedback = ""
50
+ if respiratory_score > 0.1: # Lowered from 0.5
51
  feedback += "Possible respiratory issue detected; consult a doctor. "
52
+ if mental_health_score > 0.1: # Lowered from 0.3
53
  feedback += "Possible stress indicators detected; consider professional advice. "
54
 
55
  if not feedback:
 
78
  except Exception as e:
79
  print(f"Failed to store in Salesforce: {str(e)}")
80
 
81
+ def test_with_sample_audio():
82
+ """Test the app with a sample audio file."""
83
+ sample_audio_path = "audio_samples/sample.wav" # Or "audio_samples/common_voice_sample.wav"
84
+ if os.path.exists(sample_audio_path):
85
+ return analyze_voice(sample_audio_path)
86
+ return "Sample audio file not found."
87
+
88
  # Gradio interface
89
  iface = gr.Interface(
90
  fn=analyze_voice,
 
95
  )
96
 
97
  if __name__ == "__main__":
98
+ print(test_with_sample_audio()) # Run test on startup
99
  iface.launch(server_name="0.0.0.0", server_port=7860)