tayy786 commited on
Commit
c92a360
·
verified ·
1 Parent(s): 9f16029

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ from groq import Groq
4
+
5
+ # Load API Key from environment (Hugging Face Secret)
6
+ client = Groq(api_key=os.environ.get("Keypass"))
7
+
8
+ # Chat function
9
+ def chat_with_groq(message, history):
10
+ messages = []
11
+
12
+ # Add previous chat history
13
+ for user_msg, bot_msg in history:
14
+ messages.append({"role": "user", "content": user_msg})
15
+ messages.append({"role": "assistant", "content": bot_msg})
16
+
17
+ # Add new user message
18
+ messages.append({"role": "user", "content": message})
19
+
20
+ # Groq API call
21
+ completion = client.chat.completions.create(
22
+ model="llama-3.1-8b-instant",
23
+ messages=messages,
24
+ temperature=0.7,
25
+ max_tokens=1024,
26
+ )
27
+
28
+ reply = completion.choices[0].message.content
29
+ return reply
30
+
31
+
32
+ # Gradio Chat Interface
33
+ demo = gr.ChatInterface(
34
+ fn=chat_with_groq,
35
+ title="🚀 Groq AI Chatbot",
36
+ description="Chatbot powered by Groq API + LLaMA3",
37
+ theme="soft"
38
+ )
39
+
40
+ if __name__ == "__main__":
41
+ demo.launch()