abdullahzunorain's picture
Create app.py
1559d92 verified
raw
history blame
1.16 kB
import os
from groq import Groq
from gtts import gTTS
import time
import gradio as gr
# Set up the Groq client using your API key
client = Groq(api_key=os.environ['GROQ_API_KEY'])
# Function to get chatbot response
def chatbot_response(user_input):
# Create a chat completion request
chat_completion = client.chat.completions.create(
messages=[{"role": "user", "content": user_input}],
model="llama3-8b-8192",
)
# Get the generated text
generated_text = chat_completion.choices[0].message.content.strip()
# Convert the response to speech
audio_file = f"response_{int(time.time())}.mp3"
tts = gTTS(text=generated_text, lang='en')
tts.save(audio_file)
return generated_text, audio_file
# Define Gradio interface
def respond(user_input):
response, audio_file = chatbot_response(user_input)
return response, audio_file
iface = gr.Interface(fn=respond,
inputs="text",
outputs=["text", "audio"],
title="Groq Chatbot",
description="Chat with an AI using Groq")
if __name__ == "__main__":
iface.launch()