ChatAngels / app.py
sreejang's picture
Update app.py
38bda32 verified
raw
history blame contribute delete
899 Bytes
import os
import gradio as gr
from groq import Groq
client = Groq(
api_key=os.environ.get("GROQ_API_KEY")
)
def chat_fn(user_message, history):
if history is None:
history = []
# Build clean messages for Groq (no metadata)
clean_messages = []
for msg in history:
clean_messages.append({
"role": msg["role"],
"content": msg["content"]
})
# Add current user message
clean_messages.append({
"role": "user",
"content": user_message
})
# Call Groq
response = client.chat.completions.create(
model="llama-3.3-70b-versatile",
messages=clean_messages
)
bot_reply = response.choices[0].message.content
return bot_reply
demo = gr.ChatInterface(
fn=chat_fn,
title="Groq Chat",
description="Stable Groq chatbot on Hugging Face"
)
demo.queue()
demo.launch()