Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,26 +1,25 @@
|
|
1 |
-
|
2 |
-
import gradio as gr
|
3 |
import openai
|
4 |
import os
|
5 |
import speech_recognition as sr
|
6 |
|
7 |
# Set OpenAI API Key
|
8 |
-
openai.api_key= os.getenv("TRY_NEW_THINGS")
|
9 |
openai.api_base = "https://api.groq.com/openai/v1"
|
10 |
|
11 |
# Function to get response from GROQ API
|
12 |
def get_groq_response(message):
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
|
25 |
# Function to convert speech to text
|
26 |
def speech_to_text(audio):
|
@@ -36,22 +35,20 @@ def speech_to_text(audio):
|
|
36 |
except Exception as e:
|
37 |
return f"Error in speech recognition: {str(e)}"
|
38 |
|
39 |
-
|
40 |
# Chatbot function
|
41 |
-
def chatbot(user_input,history=[]):
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
|
48 |
# Gradio Interface setup with speech-to-text functionality
|
49 |
chat_interface = gr.Interface(
|
50 |
fn=chatbot,
|
51 |
inputs=[gr.Audio(source="microphone", type="file"), "state"], # Added speech-to-text input
|
52 |
outputs=["chatbot", "state"],
|
53 |
-
live=
|
54 |
title="Meet your Personal Assistant: Your Helpful and Caring Chatbot",
|
55 |
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.",
|
56 |
)
|
|
|
57 |
chat_interface.launch()
|
|
|
1 |
+
import gradio as gr
|
|
|
2 |
import openai
|
3 |
import os
|
4 |
import speech_recognition as sr
|
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 |
def speech_to_text(audio):
|
|
|
35 |
except Exception as e:
|
36 |
return f"Error in speech recognition: {str(e)}"
|
37 |
|
|
|
38 |
# Chatbot function
|
39 |
+
def chatbot(user_input, history=[]):
|
40 |
+
bot_response = get_groq_response(user_input)
|
41 |
+
history.append((user_input, bot_response))
|
42 |
+
return history, history
|
|
|
|
|
43 |
|
44 |
# Gradio Interface setup with speech-to-text functionality
|
45 |
chat_interface = gr.Interface(
|
46 |
fn=chatbot,
|
47 |
inputs=[gr.Audio(source="microphone", type="file"), "state"], # Added speech-to-text input
|
48 |
outputs=["chatbot", "state"],
|
49 |
+
live=True,
|
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()
|