Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -5,6 +5,7 @@ from sentence_transformers import SentenceTransformer, util
|
|
5 |
import torch
|
6 |
import json
|
7 |
import urllib.parse
|
|
|
8 |
|
9 |
# Fetch Hugging Face API Token securely from environment variables
|
10 |
HF_API_TOKEN = os.getenv("HF_API_TOKEN") # This fetches the token securely
|
@@ -60,19 +61,21 @@ def get_bot_response(query):
|
|
60 |
# Gradio interface function
|
61 |
def chatbot(audio, message, system_message, max_tokens, temperature, top_p):
|
62 |
if audio is not None:
|
63 |
-
|
64 |
-
sf.write("temp.wav", audio_data, sample_rate)
|
65 |
-
|
66 |
-
|
67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
|
69 |
-
# Get the bot response using the text input or transcribed audio
|
70 |
-
response = get_bot_response(message)
|
71 |
-
|
72 |
-
# Generate the TTS audio URL
|
73 |
-
audio_url = get_tts_audio_url(response)
|
74 |
-
|
75 |
-
return response, audio_url
|
76 |
|
77 |
# Define Gradio interface
|
78 |
demo = gr.Interface(
|
|
|
5 |
import torch
|
6 |
import json
|
7 |
import urllib.parse
|
8 |
+
import soundfile as sf
|
9 |
|
10 |
# Fetch Hugging Face API Token securely from environment variables
|
11 |
HF_API_TOKEN = os.getenv("HF_API_TOKEN") # This fetches the token securely
|
|
|
61 |
# Gradio interface function
|
62 |
def chatbot(audio, message, system_message, max_tokens, temperature, top_p):
|
63 |
if audio is not None:
|
64 |
+
sample_rate, audio_data = audio # ✅ Correct order
|
65 |
+
sf.write("temp.wav", audio_data, sample_rate) # Save audio
|
66 |
+
try:
|
67 |
+
transcript = transcribe_audio("temp.wav")
|
68 |
+
message = transcript # Use transcribed text
|
69 |
+
except Exception as e:
|
70 |
+
return f"Audio transcription failed: {str(e)}", None
|
71 |
+
|
72 |
+
try:
|
73 |
+
response = get_bot_response(message)
|
74 |
+
audio_url = get_tts_audio_url(response)
|
75 |
+
return response, audio_url
|
76 |
+
except Exception as e:
|
77 |
+
return f"Error in generating response: {str(e)}", None
|
78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
|
80 |
# Define Gradio interface
|
81 |
demo = gr.Interface(
|