Spaces:
Sleeping
Sleeping
usmanyousaf
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -4,12 +4,12 @@ import uuid
|
|
4 |
from flask import Flask, request, render_template, jsonify, send_from_directory, session
|
5 |
from dotenv import load_dotenv
|
6 |
from groq import Groq
|
7 |
-
from deepgram import
|
|
|
8 |
|
9 |
# Load environment variables
|
10 |
load_dotenv()
|
11 |
|
12 |
-
|
13 |
# Fetch API keys from environment variables
|
14 |
GROQ_API_KEY = os.getenv("GROQ_API_KEY")
|
15 |
DEEPGRAM_API_KEY = os.getenv("DEEPGRAM_API_KEY")
|
@@ -39,11 +39,10 @@ def synthesize_audio(text, model="aura-asteria-en"):
|
|
39 |
unique_filename = f"therapist_response_{int(time.time())}_{uuid.uuid4().hex}.mp3"
|
40 |
filename = os.path.join(audio_folder, unique_filename)
|
41 |
|
42 |
-
|
43 |
-
|
44 |
-
)
|
45 |
-
# Synthesize the response and save it to the file
|
46 |
deepgram.speak.v("1").save(filename, {"text": text}, options)
|
|
|
47 |
return filename
|
48 |
except Exception as e:
|
49 |
raise ValueError(f"Speech synthesis failed: {str(e)}")
|
@@ -62,7 +61,6 @@ def start_chat():
|
|
62 |
session['selected_voice'] = selected_voice
|
63 |
return render_template('index.html')
|
64 |
|
65 |
-
|
66 |
@app.route('/process', methods=['POST'])
|
67 |
def process_audio():
|
68 |
global conversation_history
|
@@ -125,4 +123,5 @@ def process_audio():
|
|
125 |
return jsonify({'error': str(e)}), 500
|
126 |
|
127 |
if __name__ == '__main__':
|
128 |
-
|
|
|
|
4 |
from flask import Flask, request, render_template, jsonify, send_from_directory, session
|
5 |
from dotenv import load_dotenv
|
6 |
from groq import Groq
|
7 |
+
from deepgram import Deepgram # Adjust imports according to the official Deepgram SDK
|
8 |
+
from deepgram import SpeakOptions # This might not exist in the current SDK; adjust as needed
|
9 |
|
10 |
# Load environment variables
|
11 |
load_dotenv()
|
12 |
|
|
|
13 |
# Fetch API keys from environment variables
|
14 |
GROQ_API_KEY = os.getenv("GROQ_API_KEY")
|
15 |
DEEPGRAM_API_KEY = os.getenv("DEEPGRAM_API_KEY")
|
|
|
39 |
unique_filename = f"therapist_response_{int(time.time())}_{uuid.uuid4().hex}.mp3"
|
40 |
filename = os.path.join(audio_folder, unique_filename)
|
41 |
|
42 |
+
# The following line is based on your original usage.
|
43 |
+
# Make sure deepgram.speak and SpeakOptions usage is correct for your SDK version.
|
|
|
|
|
44 |
deepgram.speak.v("1").save(filename, {"text": text}, options)
|
45 |
+
|
46 |
return filename
|
47 |
except Exception as e:
|
48 |
raise ValueError(f"Speech synthesis failed: {str(e)}")
|
|
|
61 |
session['selected_voice'] = selected_voice
|
62 |
return render_template('index.html')
|
63 |
|
|
|
64 |
@app.route('/process', methods=['POST'])
|
65 |
def process_audio():
|
66 |
global conversation_history
|
|
|
123 |
return jsonify({'error': str(e)}), 500
|
124 |
|
125 |
if __name__ == '__main__':
|
126 |
+
# Running directly (for local testing):
|
127 |
+
app.run(host="0.0.0.0", port=7860, debug=True)
|