Spaces:
Sleeping
Sleeping
# Import libraries | |
import whisper | |
from gtts import gTTS | |
from groq import Groq | |
import os | |
import gradio as gr | |
# Load Whisper model | |
model = whisper.load_model("base") | |
GROQ_API_KEY = "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" | |
client = Groq(api_key=GROQ_API_KEY) | |
# Function to process audio | |
def process_audio(audio_path): | |
# Transcribe input audio | |
transcription = model.transcribe(audio_path)["text"] | |
# Interact with the GROQ model | |
chat_completion = client.chat.completions.create( | |
messages=[{"role": "user", "content": transcription}], | |
model="llama3-8b-8192" | |
) | |
response_text = chat_completion.choices[0].message.content | |
# Convert LLM response to audio | |
tts = gTTS(response_text) | |
response_audio_path = "response.mp3" | |
tts.save(response_audio_path) | |
return response_text, response_audio_path | |
# Gradio UI | |
with gr.Blocks() as demo: | |
gr.Markdown("### Real Voice-to-Voice Chatbot") | |
with gr.Row(): | |
input_audio = gr.Audio(type="filepath", label="Record Your Voice") | |
output_text = gr.Textbox(label="LLM Response", lines=4) | |
output_audio = gr.Audio(label="Response Audio") | |
submit_button = gr.Button("Submit") | |
submit_button.click( | |
process_audio, | |
inputs=[input_audio], | |
outputs=[output_text, output_audio], | |
) | |
demo.launch() | |