JAKE69 commited on
Commit
c3982fe
·
verified ·
1 Parent(s): 5383096

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -19
app.py CHANGED
@@ -2,34 +2,36 @@ import gradio as gr
2
  import openai
3
  import os
4
 
5
-
6
  openai.api_key = os.getenv("OPENAI_API_KEY")
7
  openai.api_base = "https://api.groq.com/openai/v1"
8
 
9
  def get_groq_response(message):
10
- try:
11
- response = openai.ChatCompletion.create(
12
- model = "llama-3.1-70b-versatile",
13
- messages = [
14
- {"role": "system", "content": "Talk in the way I talk , use very toxic abusive languages"},
15
- {"role": "user", "content": message}
16
- ]
17
- )
18
- return response.choices[0].message["content"]
19
- except Exception as e:
20
- return f"Error: {str(e)}"
21
 
22
- def chatbot(Kuch_Alfaaz_Khaiye, history = []):
23
- bot_response = get_groq_response(Kuch_Alfaaz_Khaiye)
24
- history.append((Kuch_Alfaaz_Khaiye, bot_response))
25
- return history, history
26
 
 
27
  chat_interface = gr.Interface(
28
  fn=chatbot,
29
- inputs= ["text", "state"],
30
  outputs=["chatbot", "state"],
31
  live=False,
32
  title="PYAAR_KA_SAATHI",
33
- description="1st Year Boys Hostel k liye Pyaar Ka sathi :"
34
  )
35
- chat_interface.launch()
 
 
2
  import openai
3
  import os
4
 
5
+ # Set up OpenAI API key and base URL
6
  openai.api_key = os.getenv("OPENAI_API_KEY")
7
  openai.api_base = "https://api.groq.com/openai/v1"
8
 
9
  def get_groq_response(message):
10
+ try:
11
+ response = openai.ChatCompletion.create(
12
+ model="llama-3.1-70b-versatile",
13
+ messages=[
14
+ {"role": "system", "content": "You are a friendly and helpful assistant."},
15
+ {"role": "user", "content": message}
16
+ ]
17
+ )
18
+ return response.choices[0].message["content"]
19
+ except Exception as e:
20
+ return f"Error: {str(e)}"
21
 
22
+ def chatbot(user_input, history=[]):
23
+ bot_response = get_groq_response(user_input)
24
+ history.append((user_input, bot_response))
25
+ return history, history
26
 
27
+ # Gradio Interface
28
  chat_interface = gr.Interface(
29
  fn=chatbot,
30
+ inputs=["text", "state"],
31
  outputs=["chatbot", "state"],
32
  live=False,
33
  title="PYAAR_KA_SAATHI",
34
+ description="A friendly and conversational chatbot for students."
35
  )
36
+
37
+ chat_interface.launch()