Spaces:
Build error
Build error
| import gradio as gr | |
| import os | |
| import whisper | |
| from groq import Groq | |
| from gtts import gTTS | |
| # Initialize Whisper model for transcription | |
| model = whisper.load_model("base") | |
| # Set up Groq API | |
| GROQ_API_KEY = "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" | |
| client = Groq(api_key=GROQ_API_KEY) | |
| # Function to query the LLM using Groq API | |
| def get_llm_response(input_text): | |
| chat_completion = client.chat.completions.create( | |
| messages=[{ | |
| "role": "user", | |
| "content": input_text, | |
| }], | |
| model="llama3-8b-8192", | |
| ) | |
| return chat_completion.choices[0].message.content | |
| # Function to convert text to speech using gTTS | |
| def text_to_speech(text,output_audio="output_audio.mp3"): | |
| tts = gTTS(text) | |
| tts.save(output_audio) | |
| return output_audio | |
| def chatbot(audio): | |
| result=model.transcribe(audio) | |
| user_text=result['text'] | |
| response_text=get_llm_response(user_text) | |
| output_audio=text_to_speech(response_text) | |
| return response_text,output_audio | |
| # Create Gradio interface for microphone input | |
| iface = gr.Interface( | |
| fn=chatbot, | |
| inputs=gr.Audio(type="filepath"), # Capturing audio from the microphone | |
| outputs=[gr.Textbox(),gr.Audio(type="filepath")], # Outputting audio file path | |
| live=True | |
| ) | |
| iface.launch() |