Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,3 @@
|
|
1 |
-
|
2 |
-
|
3 |
import os
|
4 |
import whisper
|
5 |
from groq import Groq
|
@@ -8,7 +6,7 @@ import tempfile
|
|
8 |
import gradio as gr
|
9 |
|
10 |
# Step 1: Set up Whisper for transcription
|
11 |
-
model = whisper.load_model("base")
|
12 |
|
13 |
# Function to transcribe audio using Whisper
|
14 |
def transcribe_audio(audio_file):
|
@@ -31,11 +29,9 @@ def get_groq_response(text):
|
|
31 |
# Step 3: Convert text response from LLM to speech using GTTS
|
32 |
def text_to_speech(text):
|
33 |
tts = gTTS(text)
|
34 |
-
|
35 |
# Save the audio to a temporary file
|
36 |
temp_file = tempfile.NamedTemporaryFile(delete=False)
|
37 |
tts.save(temp_file.name)
|
38 |
-
|
39 |
# Return the file path for Gradio to play the audio
|
40 |
return temp_file.name
|
41 |
|
@@ -43,18 +39,15 @@ def text_to_speech(text):
|
|
43 |
def voice_chatbot(audio_input):
|
44 |
# Step 1: Transcribe the audio using Whisper
|
45 |
transcription = transcribe_audio(audio_input)
|
46 |
-
|
47 |
# Step 2: Get response from Groq API using the transcription
|
48 |
response = get_groq_response(transcription)
|
49 |
-
|
50 |
# Step 3: Convert the response text to speech using GTTS
|
51 |
audio_response = text_to_speech(response)
|
52 |
-
|
53 |
# Return the audio response (Gradio will play it)
|
54 |
return audio_response
|
55 |
|
56 |
# Step 5: Create the Gradio interface (microphone input and audio output)
|
57 |
-
iface = gr.Interface(fn=voice_chatbot,
|
58 |
inputs=gr.Audio(type="filepath"), # No source="microphone" argument
|
59 |
outputs=gr.Audio(),
|
60 |
live=True)
|
|
|
|
|
|
|
1 |
import os
|
2 |
import whisper
|
3 |
from groq import Groq
|
|
|
6 |
import gradio as gr
|
7 |
|
8 |
# Step 1: Set up Whisper for transcription
|
9 |
+
model = whisper.load_model("base") # Ensure correct version of whisper is installed
|
10 |
|
11 |
# Function to transcribe audio using Whisper
|
12 |
def transcribe_audio(audio_file):
|
|
|
29 |
# Step 3: Convert text response from LLM to speech using GTTS
|
30 |
def text_to_speech(text):
|
31 |
tts = gTTS(text)
|
|
|
32 |
# Save the audio to a temporary file
|
33 |
temp_file = tempfile.NamedTemporaryFile(delete=False)
|
34 |
tts.save(temp_file.name)
|
|
|
35 |
# Return the file path for Gradio to play the audio
|
36 |
return temp_file.name
|
37 |
|
|
|
39 |
def voice_chatbot(audio_input):
|
40 |
# Step 1: Transcribe the audio using Whisper
|
41 |
transcription = transcribe_audio(audio_input)
|
|
|
42 |
# Step 2: Get response from Groq API using the transcription
|
43 |
response = get_groq_response(transcription)
|
|
|
44 |
# Step 3: Convert the response text to speech using GTTS
|
45 |
audio_response = text_to_speech(response)
|
|
|
46 |
# Return the audio response (Gradio will play it)
|
47 |
return audio_response
|
48 |
|
49 |
# Step 5: Create the Gradio interface (microphone input and audio output)
|
50 |
+
iface = gr.Interface(fn=voice_chatbot,
|
51 |
inputs=gr.Audio(type="filepath"), # No source="microphone" argument
|
52 |
outputs=gr.Audio(),
|
53 |
live=True)
|