arpit13 commited on
Commit
1f183a9
·
verified ·
1 Parent(s): 485cda7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -34
app.py CHANGED
@@ -1,48 +1,41 @@
1
- import gradio as gr
2
  import openai
3
  import os
4
- import openai-whisper
5
 
6
  # Set OpenAI API Key
7
- openai.api_key = os.getenv("TRY_NEW_THINGS")
8
  openai.api_base = "https://api.groq.com/openai/v1"
9
 
10
  # Function to get response from GROQ API
11
  def get_groq_response(message):
12
- try:
13
- response = openai.ChatCompletion.create(
14
- model="llama-3.1-70b-versatile",
15
- messages=[
16
- {"role": "system", "content": "From now on answer in way terrorist trying to flirt "},
17
- {"role": "user", "content": message}
18
- ]
19
- )
20
- return response.choices[0].message["content"]
21
- except Exception as e:
22
- return f"Error: {str(e)}"
23
 
24
- # Function to convert speech to text
25
-
26
- def speech_to_text(audio):
27
- model = whisper.load_model("base") # Or any model size you prefer
28
- result = model.transcribe(audio.name) # Use the audio file
29
- return result['text']
30
 
31
 
32
  # Chatbot function
33
- def chatbot(user_input, history=[]):
34
- bot_response = get_groq_response(user_input)
35
- history.append((user_input, bot_response))
36
- return history, history
37
 
38
- # Gradio Interface setup with speech-to-text functionality
39
  chat_interface = gr.Interface(
40
- fn=chatbot,
41
- inputs=[gr.Audio(source="microphone", type="file"), "state"], # Added speech-to-text input
42
- outputs=["chatbot", "state"],
43
- live=True,
44
- title="Meet your Personal Assistant: Your Helpful and Caring Chatbot",
45
- 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.",
46
- )
47
-
48
- 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):
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()