saherPervaiz commited on
Commit
24d27ed
·
verified ·
1 Parent(s): 529d9fe

Rename app.py to config.py

Browse files
Files changed (2) hide show
  1. app.py +0 -46
  2. config.py +5 -0
app.py DELETED
@@ -1,46 +0,0 @@
1
- import gradio as gr
2
- from groq.client import Client # Adjust this based on Groq's official documentation
3
-
4
- # Initialize Groq API client
5
- api_key = "your_groq_api_key" # Replace with your actual API key
6
- client = Client(api_key=api_key)
7
-
8
- # Chatbot logic using Groq API
9
- def chatbot(message, history):
10
- history = history or [] # Initialize history if None
11
-
12
- # Build a prompt using the chat history
13
- prompt = "\n".join([f"User: {msg[0]}\nBot: {msg[1]}" for msg in history])
14
- prompt += f"\nUser: {message}\nBot:"
15
-
16
- # Query the Groq API
17
- response = client.chat.completions.create(
18
- messages=[{"role": "user", "content": prompt}],
19
- model="llama-3.3-70b-versatile", # Adjust the model name if necessary
20
- )
21
- bot_reply = response.choices[0].message.content.strip() # Extract the reply
22
-
23
- # Append the conversation to history
24
- history.append((message, bot_reply))
25
- return history, history
26
-
27
- # Gradio Interface
28
- with gr.Blocks() as demo:
29
- gr.Markdown("# Gradio Chatbot with Groq API")
30
- chatbot_ui = gr.Chatbot(label="Chatbot") # Chatbot display
31
- with gr.Row():
32
- user_input = gr.Textbox(placeholder="Type your message here...") # Input box
33
- submit_btn = gr.Button("Send") # Send button
34
-
35
- # Clear history button
36
- clear_btn = gr.Button("Clear Chat")
37
-
38
- # State management for chat history
39
- state = gr.State()
40
-
41
- # Event bindings
42
- submit_btn.click(chatbot, inputs=[user_input, state], outputs=[chatbot_ui, state])
43
- clear_btn.click(lambda: ([], None), outputs=[chatbot_ui, state])
44
-
45
- # Launch the app
46
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
config.py ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ import os
2
+
3
+ # Configuration for Groq API
4
+ GROQ_API_KEY = os.getenv("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")
5
+ MODEL_NAME = "llama-3.3-70b-versatile"