Simple_Chat_Bot / app.py
Amelia-James's picture
Create app.py
23ed574 verified
import os
import gradio as gr
from groq import Groq
def load_api_key():
api_key = os.getenv("GROQ_API_KEY")
if api_key:
return api_key
try:
from google.colab import userdata
api_key = userdata.get("GROQ_API_KEY")
return api_key
except:
pass
raise ValueError("GROQ_API_KEY not found.")
GROQ_API_KEY = load_api_key()
client = Groq(api_key=GROQ_API_KEY)
def chat_with_ai(message, history):
chat_completion = client.chat.completions.create(
messages=[
{"role": "user", "content": message}
],
model="llama-3.3-70b-versatile",
)
return chat_completion.choices[0].message.content
with gr.Blocks() as demo:
gr.Markdown("# 🤖 Groq AI Chatbot")
gr.Markdown(
"AI chatbot powered by **Groq Llama-3.3-70B**."
)
chatbot = gr.ChatInterface(
fn=chat_with_ai,
textbox=gr.Textbox(
placeholder="Type your message..."
)
)
demo.launch()