Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- requirements.txt +5 -0
- voice_chatbot.py +66 -0
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
groq
|
3 |
+
openai-whisper
|
4 |
+
pyttsx3
|
5 |
+
gtts
|
voice_chatbot.py
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# -*- coding: utf-8 -*-
|
2 |
+
|
3 |
+
|
4 |
+
import os
|
5 |
+
import gradio as gr
|
6 |
+
import whisper
|
7 |
+
from gtts import gTTS
|
8 |
+
from groq import Groq
|
9 |
+
|
10 |
+
# Set up Groq API client
|
11 |
+
client = Groq(
|
12 |
+
api_key="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",
|
13 |
+
)
|
14 |
+
# Load Whisper model
|
15 |
+
model = whisper.load_model("base")
|
16 |
+
|
17 |
+
def chatbot(audio):
|
18 |
+
# Transcribe the audio input using Whisper
|
19 |
+
transcription = model.transcribe(audio)
|
20 |
+
user_input = transcription["text"]
|
21 |
+
|
22 |
+
# Generate a response using Llama 8B via Groq API
|
23 |
+
chat_completion = client.chat.completions.create(
|
24 |
+
messages=[
|
25 |
+
{
|
26 |
+
"role": "user",
|
27 |
+
"content": user_input,
|
28 |
+
}
|
29 |
+
],
|
30 |
+
model="llama3-8b-8192",
|
31 |
+
)
|
32 |
+
response_text = chat_completion.choices[0].message.content
|
33 |
+
|
34 |
+
# Convert the response text to speech using gTTS
|
35 |
+
tts = gTTS(text=response_text, lang='en')
|
36 |
+
tts.save("response.mp3")
|
37 |
+
|
38 |
+
return response_text, "response.mp3"
|
39 |
+
|
40 |
+
# Create a custom interface
|
41 |
+
def build_interface():
|
42 |
+
with gr.Blocks() as demo:
|
43 |
+
gr.Markdown(
|
44 |
+
"""
|
45 |
+
<h1 style="text-align: center; color: #4CAF50;">Voice-to-Voice Chatbot</h1>
|
46 |
+
<h3 style="text-align: center;">Powered by OpenAI Whisper, Llama 8B, and gTTS</h3>
|
47 |
+
<p style="text-align: center;">Talk to the AI-powered chatbot and get responses in real-time. Start by recording your voice.</p>
|
48 |
+
"""
|
49 |
+
)
|
50 |
+
with gr.Row():
|
51 |
+
with gr.Column(scale=1):
|
52 |
+
audio_input = gr.Audio(type="filepath", label="Record Your Voice")
|
53 |
+
with gr.Column(scale=2):
|
54 |
+
chatbot_output_text = gr.Textbox(label="Chatbot Response")
|
55 |
+
chatbot_output_audio = gr.Audio(label="Audio Response")
|
56 |
+
|
57 |
+
submit_button = gr.Button("Submit")
|
58 |
+
|
59 |
+
submit_button.click(chatbot, inputs=audio_input, outputs=[chatbot_output_text, chatbot_output_audio])
|
60 |
+
|
61 |
+
return demo
|
62 |
+
|
63 |
+
# Launch the interface
|
64 |
+
if __name__ == "__main__":
|
65 |
+
interface = build_interface()
|
66 |
+
interface.launch()
|