arpit13 commited on
Commit
8df15f7
·
verified ·
1 Parent(s): cb36665

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -27
app.py CHANGED
@@ -1,41 +1,54 @@
1
- import gradio as gr
2
  import openai
3
  import os
4
 
5
  # Set OpenAI API Key
6
- openai.api_key= os.getenv("TRY_NEW_THINGS")
7
  openai.api_base = "https://api.groq.com/openai/v1"
8
 
9
  # Function to get response from GROQ API
10
- def get_groq_response(message):
11
- try:
12
- response = openai.ChatCompletion.create(
13
- model = "llama-3.1-70b-versatile",
14
- messages = [
15
- {"role":"system","content":"From now on answer in way terrorist trying to flirt "},
16
- {"role": "user","content":message}
17
- ]
18
- )
19
- return response.choices[0].message["content"]
20
- except Exception as e:
21
- return f"Error:{str(e)}"
22
-
23
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
  # Chatbot function
26
- def chatbot(user_input,history=[]):
27
- bot_response = get_groq_response(user_input)
28
- history.append((user_input,bot_response))
29
- return history,history
30
 
31
  # Gradio Interface setup
32
  chat_interface = gr.Interface(
33
- fn = chatbot,
34
- inputs = ["text","state"],
35
- outputs = ["chatbot","state"],
36
- live = True,
37
- title ="Meet your Personal Assistant: Your Helpful and Caring Chatbot",
38
- description ="This chatbot is here to help you with anything you need, whether it’s answering questions, offering support, or guiding you through tasks. With a friendly and empathetic approach, it listens carefully to your concerns and provides thoughtful, understanding responses. Whether you’re seeking information or just someone to chat with, our chatbot is designed to make you feel heard and supported. It’s more than just a tool—it’s a companion dedicated to making your day easier and more enjoyable"
39
- )
 
 
 
 
40
 
41
- chat_interface.launch()
 
1
+ import gradio as gr
2
  import openai
3
  import os
4
 
5
  # Set OpenAI API Key
6
+ openai.api_key = os.getenv("TRY_NEW_THINGS")
7
  openai.api_base = "https://api.groq.com/openai/v1"
8
 
9
  # Function to get response from GROQ API
10
+ def get_groq_response(message, category):
11
+ # System message to tailor responses based on the category
12
+ system_message = ""
13
+ if category == "Stress Management":
14
+ system_message = "Provide soothing advice and tips to help the user manage stress. Be calm and empathetic."
15
+ elif category == "Career Advice":
16
+ system_message = "Provide professional and constructive career advice. Be encouraging and helpful."
17
+ elif category == "General":
18
+ system_message = "Provide general conversation. Be friendly and easygoing."
19
+ elif category == "Friendly Buddy":
20
+ system_message = "Respond as a supportive and fun friend. Be informal and light-hearted."
 
 
21
 
22
+ try:
23
+ response = openai.ChatCompletion.create(
24
+ model="llama-3.1-70b-versatile",
25
+ messages=[
26
+ {"role": "system", "content": system_message},
27
+ {"role": "user", "content": message}
28
+ ]
29
+ )
30
+ return response.choices[0].message["content"]
31
+ except Exception as e:
32
+ return f"Error: {str(e)}"
33
 
34
  # Chatbot function
35
+ def chatbot(user_input, category, history=[]):
36
+ bot_response = get_groq_response(user_input, category)
37
+ history.append((user_input, bot_response))
38
+ return history, history
39
 
40
  # Gradio Interface setup
41
  chat_interface = gr.Interface(
42
+ fn=chatbot,
43
+ inputs=[
44
+ "text", # User input
45
+ gr.Dropdown(choices=["Stress Management", "Career Advice", "General", "Friendly Buddy"], label="Choose Chat Category"), # Category selection
46
+ "state" # History
47
+ ],
48
+ outputs=["chatbot", "state"],
49
+ live=False,
50
+ title="Meet your Personal Assistant: Your Helpful and Caring Chatbot",
51
+ description="This chatbot is here to help you with anything you need, whether it’s answering questions, offering support, or guiding you through tasks. With a friendly and empathetic approach, it listens carefully to your concerns and provides thoughtful, understanding responses. Whether you’re seeking information or just someone to chat with, our chatbot is designed to make you feel heard and supported. It’s more than just a tool—it’s a companion dedicated to making your day easier and more enjoyable."
52
+ )
53
 
54
+ chat_interface.launch()