Spaces:
Sleeping
Sleeping
File size: 2,028 Bytes
6cc5a1c 14a2888 e7e342c 14a2888 50a66b5 e7e342c 5782555 5a93e47 50a66b5 5782555 e7e342c 14a2888 e7e342c 14a2888 e7e342c 14a2888 e7e342c 14a2888 e7e342c 14a2888 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
import openai
import gradio as gr
import osn
openai.api_key = os.getenv("OPENAI_API_KEY")
from transformers import pipeline
p = pipeline("automatic-speech-recognition",model="openai/whisper-tiny")
def transcribe(audio):
text = p(audio)["text"]
return text
def sentiment(text):
response = openai.Completion.create(
model="text-davinci-003",
prompt=f"calssify the text into below sentiment category\n\ntext : {text}\"\n\n['angry','happy','satify','neutral']\n",
temperature=1,
max_tokens=256,
top_p=1,
frequency_penalty=0,
presence_penalty=0)
return response.choices[0].text.strip()
messages = [
{"role": "system",
"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"}
]
def chatbot(input):
if input:
input = transcribe(input)
messages.append({"role": "user", "content": input})
if sentiment(input) == 'angry':
reply = "Sorry for any inconvinience. We are tranfering your call."
else:
chat = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=messages,
temperature=0.2,
max_tokens=320,
top_p=1,
frequency_penalty=0,
presence_penalty=0)
reply = chat.choices[0].message.content
messages.append({"role": "assistant", "content": reply})
return reply
##inputs = gr.inputs.Textbox(lines=7, label="Chat with PepsiCo AI assitant")
inputs= gr.Audio(source="microphone", type="filepath")
outputs = gr.outputs.Textbox(label="Reply")
gr.Interface(fn= chatbot,
inputs= inputs,
outputs= outputs,
title="chatbot",
description="Ask anything you want",
theme="compact").launch()
# gr.Interface(
# fn=transcribe,
# inputs= inputs,
# outputs="text"
# ).launch()
|