ChatBot / app.py
CodeNine's picture
Create app.py
99ca370 verified
raw
history blame
966 Bytes
# app.py
import os
from groq import Groq
import gradio as gr
from dotenv import load_dotenv
# Load .env file (contains your API key)
load_dotenv()
client = Groq(api_key=os.environ.get("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"))
def groq_chat(message, history):
messages = [{"role": "system", "content": "You are a helpful assistant."}]
for user, bot in history:
messages.append({"role": "user", "content": user})
messages.append({"role": "assistant", "content": bot})
messages.append({"role": "user", "content": message})
response = client.chat.completions.create(
model="llama-3.3-70b-versatile", # Change model if needed
messages=messages,
temperature=0.7,
)
return response.choices[0].message.content
demo = gr.ChatInterface(
fn=groq_chat,
title="Groq Chatbot",
description="Chat with a lightning-fast LLM via Groq API",
theme=gr.themes.Soft()
)
demo.launch()