|
import os |
|
from groq import Groq |
|
from gtts import gTTS |
|
import time |
|
import gradio as gr |
|
|
|
|
|
client = Groq(api_key=os.environ['GROQ_API_KEY']) |
|
|
|
|
|
def chatbot_response(user_input): |
|
|
|
chat_completion = client.chat.completions.create( |
|
messages=[{"role": "user", "content": user_input}], |
|
model="llama3-8b-8192", |
|
) |
|
|
|
generated_text = chat_completion.choices[0].message.content.strip() |
|
|
|
|
|
audio_file = f"response_{int(time.time())}.mp3" |
|
tts = gTTS(text=generated_text, lang='en') |
|
tts.save(audio_file) |
|
|
|
return generated_text, audio_file |
|
|
|
|
|
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() |
|
|