Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,10 @@
|
|
1 |
|
2 |
import openai
|
3 |
import gradio as gr
|
4 |
-
import
|
5 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
6 |
|
|
|
7 |
from transformers import pipeline
|
8 |
p = pipeline("automatic-speech-recognition",model="openai/whisper-tiny")
|
9 |
|
@@ -11,33 +12,40 @@ def transcribe(audio):
|
|
11 |
text = p(audio)["text"]
|
12 |
return text
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
21 |
|
22 |
messages = [
|
23 |
{"role": "system",
|
24 |
-
"content": "you name is Rebecca and you are a Pepsico call center assistant and your job is to take the order from the customer"}
|
25 |
]
|
26 |
|
27 |
def chatbot(input):
|
28 |
if input:
|
29 |
input = transcribe(input)
|
30 |
messages.append({"role": "user", "content": input})
|
31 |
-
|
|
|
|
|
|
|
32 |
model="gpt-3.5-turbo",
|
33 |
messages=messages,
|
34 |
temperature=0.2,
|
35 |
max_tokens=320,
|
36 |
top_p=1,
|
37 |
frequency_penalty=0,
|
38 |
-
presence_penalty=0
|
39 |
-
|
40 |
-
|
41 |
messages.append({"role": "assistant", "content": reply})
|
42 |
return reply
|
43 |
|
@@ -49,8 +57,8 @@ inputs= gr.Audio(source="microphone", type="filepath")
|
|
49 |
outputs = gr.outputs.Textbox(label="Reply")
|
50 |
|
51 |
gr.Interface(fn= chatbot,
|
52 |
-
inputs=inputs,
|
53 |
-
outputs=outputs,
|
54 |
title="chatbot",
|
55 |
description="Ask anything you want",
|
56 |
theme="compact").launch()
|
|
|
1 |
|
2 |
import openai
|
3 |
import gradio as gr
|
4 |
+
import osn
|
5 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
6 |
|
7 |
+
|
8 |
from transformers import pipeline
|
9 |
p = pipeline("automatic-speech-recognition",model="openai/whisper-tiny")
|
10 |
|
|
|
12 |
text = p(audio)["text"]
|
13 |
return text
|
14 |
|
15 |
+
def sentiment(text):
|
16 |
+
response = openai.Completion.create(
|
17 |
+
model="text-davinci-003",
|
18 |
+
prompt=f"calssify the text into below sentiment category\n\ntext : {text}\"\n\n['angry','happy','satify','neutral']\n",
|
19 |
+
temperature=1,
|
20 |
+
max_tokens=256,
|
21 |
+
top_p=1,
|
22 |
+
frequency_penalty=0,
|
23 |
+
presence_penalty=0)
|
24 |
+
return response.choices[0].text.strip()
|
25 |
+
|
26 |
|
27 |
messages = [
|
28 |
{"role": "system",
|
29 |
+
"content": "you name is Rebecca and you are a Pepsico call center assistant and your job is to take the order from the customer and also analysis the sentiment of the customer"}
|
30 |
]
|
31 |
|
32 |
def chatbot(input):
|
33 |
if input:
|
34 |
input = transcribe(input)
|
35 |
messages.append({"role": "user", "content": input})
|
36 |
+
if sentiment(input) == 'angry':
|
37 |
+
reply = "Sorry for any inconvinience. We are tranfering your call."
|
38 |
+
else:
|
39 |
+
chat = openai.ChatCompletion.create(
|
40 |
model="gpt-3.5-turbo",
|
41 |
messages=messages,
|
42 |
temperature=0.2,
|
43 |
max_tokens=320,
|
44 |
top_p=1,
|
45 |
frequency_penalty=0,
|
46 |
+
presence_penalty=0)
|
47 |
+
reply = chat.choices[0].message.content
|
48 |
+
|
49 |
messages.append({"role": "assistant", "content": reply})
|
50 |
return reply
|
51 |
|
|
|
57 |
outputs = gr.outputs.Textbox(label="Reply")
|
58 |
|
59 |
gr.Interface(fn= chatbot,
|
60 |
+
inputs= inputs,
|
61 |
+
outputs= outputs,
|
62 |
title="chatbot",
|
63 |
description="Ask anything you want",
|
64 |
theme="compact").launch()
|