Amelia-James commited on
Commit
23ed574
·
verified ·
1 Parent(s): ab33751

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -0
app.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ from groq import Groq
4
+
5
+
6
+ def load_api_key():
7
+
8
+ api_key = os.getenv("GROQ_API_KEY")
9
+
10
+ if api_key:
11
+ return api_key
12
+
13
+ try:
14
+ from google.colab import userdata
15
+ api_key = userdata.get("GROQ_API_KEY")
16
+ return api_key
17
+ except:
18
+ pass
19
+
20
+ raise ValueError("GROQ_API_KEY not found.")
21
+
22
+
23
+ GROQ_API_KEY = load_api_key()
24
+
25
+ client = Groq(api_key=GROQ_API_KEY)
26
+
27
+
28
+ def chat_with_ai(message, history):
29
+
30
+ chat_completion = client.chat.completions.create(
31
+ messages=[
32
+ {"role": "user", "content": message}
33
+ ],
34
+ model="llama-3.3-70b-versatile",
35
+ )
36
+
37
+ return chat_completion.choices[0].message.content
38
+
39
+
40
+ with gr.Blocks() as demo:
41
+
42
+ gr.Markdown("# 🤖 Groq AI Chatbot")
43
+
44
+ gr.Markdown(
45
+ "AI chatbot powered by **Groq Llama-3.3-70B**."
46
+ )
47
+
48
+ chatbot = gr.ChatInterface(
49
+ fn=chat_with_ai,
50
+ textbox=gr.Textbox(
51
+ placeholder="Type your message..."
52
+ )
53
+ )
54
+
55
+
56
+ demo.launch()