Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,48 +1,41 @@
|
|
1 |
-
import
|
2 |
import openai
|
3 |
import os
|
4 |
-
import openai-whisper
|
5 |
|
6 |
# Set OpenAI API Key
|
7 |
-
openai.api_key
|
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 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
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,
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
|
38 |
-
# Gradio Interface setup
|
39 |
chat_interface = gr.Interface(
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
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()
|