SatyamSinghal commited on
Commit
f763b98
·
verified ·
1 Parent(s): db94ff8

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 openai
3
+ imoprt os
4
+
5
+ openai.api_key = os.getenv("GROQ_API_KEY")
6
+ openai.api_base = "https://api.groq.com/openai/v1"
7
+
8
+ def get_groq_response(message):
9
+ try:
10
+ response = openai.ChatCompletion.create(
11
+ model = "llama-3.1-70b-versatile",
12
+ messages = [
13
+ {"role" : "user", "content": "Main baat nhi krunga bhidu 😂"}
14
+ ]
15
+ )
16
+ return response.choices[0].message["content"]
17
+ except Exception as e:
18
+ return f"Error: {str(e)}"
19
+
20
+ def chatbot(user_input, history=[]):
21
+ # Get the response from Groq model
22
+ bot_response = get_groq_response(user_input)
23
+ history.append((user_input, bot_response)) # Append the conversation to history
24
+ return history, history # Return history and updated state
25
+
26
+ # Gradio Interface setup
27
+ chat_interface = gr.Interface(
28
+ fn=chatbot, # Function to call for chatbot interaction
29
+ inputs=["text","state"], # Input fields: user message and chat history (state)
30
+ outputs=["chatbot","state"], # Outputs: the chat and the updated history (state)
31
+ live=False, # Disable live chat, responses will be shown after submit
32
+ title="My Chatbot", # Title of the app
33
+ description="Apan Tapori hai bhidu, kitna hi krle answer ni dega apun 😂 \nChatGPT at home:" )
34
+ chat_interface.launch()