Katlinsky, Ilya commited on
Commit
d721bdd
·
1 Parent(s): efba8f4

feat: add text to speach reply

Browse files
Files changed (1) hide show
  1. app.py +9 -10
app.py CHANGED
@@ -1,8 +1,8 @@
1
- import os
2
-
3
  import gradio as gr
4
  import openai
 
5
  from dotenv import load_dotenv
 
6
 
7
  load_dotenv()
8
 
@@ -11,16 +11,15 @@ messages = [{"role": "system", "content": "You are a software architect"}]
11
 
12
 
13
  def process(request):
14
- print(request)
15
- file = open(request, "rb")
16
- print(file)
17
- transcription = openai.Audio.transcribe("whisper-1", file)
18
-
19
- messages.append({"role": "user", "content": transcription["text"]})
20
  completion = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=messages)
 
21
 
22
- messages.append({"role": "assistant", "content": completion.choices[0].message.content})
 
 
23
 
 
24
  res = ''
25
  for message in messages:
26
  if message["role"] == "system":
@@ -31,7 +30,7 @@ def process(request):
31
  return res
32
 
33
 
34
- question_box = gr.Audio(label="Ask question to assistant", type='filepath', source='microphone')
35
  chat_log_box = gr.Textbox(label="Chat Log", max_lines=150)
36
 
37
  ui = gr.Interface(fn=process, inputs=question_box, outputs=chat_log_box)
 
 
 
1
  import gradio as gr
2
  import openai
3
+ import os
4
  from dotenv import load_dotenv
5
+ import pyttsx3
6
 
7
  load_dotenv()
8
 
 
11
 
12
 
13
  def process(request):
14
+ messages.append({"role": "user", "content": request})
 
 
 
 
 
15
  completion = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=messages)
16
+ reply = completion.choices[0].message.content
17
 
18
+ engine = pyttsx3.init()
19
+ engine.say(reply)
20
+ engine.runAndWait()
21
 
22
+ messages.append({"role": "assistant", "content": reply})
23
  res = ''
24
  for message in messages:
25
  if message["role"] == "system":
 
30
  return res
31
 
32
 
33
+ question_box = gr.Textbox(label="Ask question to assistant")
34
  chat_log_box = gr.Textbox(label="Chat Log", max_lines=150)
35
 
36
  ui = gr.Interface(fn=process, inputs=question_box, outputs=chat_log_box)