saherPervaiz commited on
Commit
7e75850
·
verified ·
1 Parent(s): e0621f9

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ from groq import Groq
4
+
5
+ # Initialize Groq client
6
+ client = Groq(api_key="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")
7
+
8
+ # Chat function
9
+ def chat_with_groq(user_input):
10
+ try:
11
+ # Create a chat completion request
12
+ chat_completion = client.chat.completions.create(
13
+ messages=[
14
+ {"role": "user", "content": user_input},
15
+ ],
16
+ model="llama-3.3-70b-versatile",
17
+ )
18
+ # Return the AI's response
19
+ return chat_completion.choices[0].message.content
20
+ except Exception as e:
21
+ return f"Error: {e}"
22
+
23
+ # Gradio interface
24
+ iface = gr.Interface(
25
+ fn=chat_with_groq,
26
+ inputs="text",
27
+ outputs="text",
28
+ title="Groq Chatbot",
29
+ description="A chatbot powered by Groq API and Gradio."
30
+ )
31
+
32
+ # Launch locally
33
+ if __name__ == "__main__":
34
+ iface.launch()