maria355's picture
Update app.py
d89b50d verified
raw
history blame contribute delete
897 Bytes
import os
import gradio as gr
from groq import Groq
# Get API key from environment variable set in Hugging Face secrets
GROQ_API_KEY = os.getenv("GROQ_API_KEY")
# Initialize the Groq client
client = Groq(api_key=GROQ_API_KEY)
# Chatbot logic
def chat_with_groq(message):
try:
chat_completion = client.chat.completions.create(
messages=[{"role": "user", "content": message}],
model="llama-3.3-70b-versatile",
stream=False,
)
return chat_completion.choices[0].message.content
except Exception as e:
return f"Error: {str(e)}"
# Gradio interface
def chatbot_interface(user_input):
return chat_with_groq(user_input)
iface = gr.Interface(
fn=chatbot_interface,
inputs="text",
outputs="text",
title="🤖 Your Conversational Agent",
description="Chat with the Groq-powered chatbot."
)
iface.launch()