syeda-Rija20 commited on
Commit
dcd38cb
·
verified ·
1 Parent(s): 3b6cd16

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from groq import Groq
3
+ import gradio as gr
4
+
5
+ # Get API key securely from Hugging Face secrets
6
+ client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
7
+
8
+ def chatbot(message, history):
9
+ messages = [{"role": "system", "content": "You are a helpful AI assistant."}]
10
+
11
+ for user, bot in history:
12
+ messages.append({"role": "user", "content": user})
13
+ messages.append({"role": "assistant", "content": bot})
14
+
15
+ messages.append({"role": "user", "content": message})
16
+
17
+ response = client.chat.completions.create(
18
+ messages=messages,
19
+ model="llama-3.3-70b-versatile",
20
+ )
21
+
22
+ return response.choices[0].message.content
23
+
24
+ gr.ChatInterface(
25
+ fn=chatbot,
26
+ title="🚀 Groq AI Chatbot",
27
+ description="Fast chatbot using Groq + Llama",
28
+ ).launch()