gradioapp commited on
Commit
da44e90
·
1 Parent(s): 6d6a1d2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -3
app.py CHANGED
@@ -7,6 +7,9 @@ openai.api_key = os.getenv("OPENAI_API_KEY")
7
  from transformers import pipeline
8
  p = pipeline("automatic-speech-recognition",model="openai/whisper-tiny")
9
 
 
 
 
10
  def transcribe(audio):
11
  text = p(audio)["text"]
12
  return text
@@ -28,8 +31,8 @@ messages = [
28
  "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"}
29
  ]
30
 
31
- def chatbot(input):
32
- if input:
33
  input = transcribe(input)
34
  messages.append({"role": "user", "content": input})
35
  if sentiment(input) == 'negative':
@@ -47,10 +50,32 @@ def chatbot(input):
47
 
48
  messages.append({"role": "assistant", "content": reply})
49
  return reply
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
 
 
51
  ##inputs = gr.inputs.Textbox(lines=7, label="Chat with PepsiCo AI assitant")
52
 
53
- inputs= gr.Audio(source="microphone", type="filepath")
 
 
 
54
 
55
 
56
  outputs = gr.outputs.Textbox(label="Reply")
 
7
  from transformers import pipeline
8
  p = pipeline("automatic-speech-recognition",model="openai/whisper-tiny")
9
 
10
+
11
+
12
+
13
  def transcribe(audio):
14
  text = p(audio)["text"]
15
  return text
 
31
  "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"}
32
  ]
33
 
34
+ def chatbot(input1,input2):
35
+ if input1:
36
  input = transcribe(input)
37
  messages.append({"role": "user", "content": input})
38
  if sentiment(input) == 'negative':
 
50
 
51
  messages.append({"role": "assistant", "content": reply})
52
  return reply
53
+ elif input2:
54
+ input =input2
55
+ messages.append({"role": "user", "content": input})
56
+ if sentiment(input) == 'negative':
57
+ reply = "Sorry for any inconvinience. We are tranfering your call."
58
+ else:
59
+ chat = openai.ChatCompletion.create(
60
+ model="gpt-3.5-turbo",
61
+ messages=messages,
62
+ temperature=0.2,
63
+ max_tokens=320,
64
+ top_p=1,
65
+ frequency_penalty=0,
66
+ presence_penalty=0)
67
+ reply = chat.choices[0].message.content
68
+
69
+ messages.append({"role": "assistant", "content": reply})
70
+ return reply
71
 
72
+
73
  ##inputs = gr.inputs.Textbox(lines=7, label="Chat with PepsiCo AI assitant")
74
 
75
+ #inputs= gr.Audio(source="microphone", type="filepath")
76
+
77
+ inputs= [ gr.Audio(source="microphone", type="filepath"),
78
+ gr.inputs.Textbox(lines=7)]
79
 
80
 
81
  outputs = gr.outputs.Textbox(label="Reply")