arpit13 commited on
Commit
4f99602
·
verified ·
1 Parent(s): 176d0b8

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
+ impport 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":"system","content":"From now on answer in flurting in hindi and english mix"},
14
+ {"role": "user","content":message}
15
+ ]
16
+ )
17
+ return response.choices[0].message["content"]
18
+ except Exception as e:
19
+ return f"Error:{str(e)}"
20
+
21
+ def chatbot(user_input,history=[]):
22
+ bot_response = get_groq_response(user_input)
23
+ history.append((user_input,bot_response))
24
+ return history,history
25
+
26
+ chat_interface = gr.Interface(
27
+ fn = chatbot,
28
+ inputs = ["text","state"],
29
+ outputs = ["chatbot","state"],
30
+ live = False,
31
+ title ="My Chatbot",
32
+ description ="Chatbot at home"
33
+ )
34
+ chat_interface.launch()