hwberry2 commited on
Commit
24f06d9
·
1 Parent(s): a110eb7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -22
app.py CHANGED
@@ -6,23 +6,27 @@ from gtts import gTTS
6
 
7
  openai.api_key = os.environ["OPEN_AI_KEY"]
8
 
9
-
10
- with gr.Blocks() as demo:
11
- messages = gr.State(value=[{"role": "system", "content": "You are a therapist. Respond in less than 5 sentences."}])
12
- #messages = [{"role": "system", "content": "You are a therapist. Respond in less than 5 sentences."}]
13
-
14
-
15
- def transcribe(audio):
16
  audio_file = open(audio, "rb")
17
  # Call the transcribe method with the file-like object
18
  transcript = openai.Audio.transcribe("whisper-1", audio_file)
19
 
20
  return transcript["text"]
21
 
22
- def botResponse(user_input, messages):
23
- #global messages
24
- #messages = msg_contents
25
 
 
 
 
 
 
 
 
 
 
 
26
  messages.append({"role": "user", "content": user_input})
27
  response = openai.ChatCompletion.create(
28
  model="gpt-3.5-turbo",
@@ -39,18 +43,6 @@ with gr.Blocks() as demo:
39
 
40
  return chat_transcript
41
 
42
- def giveVoice(bot_message):
43
- myobj = gTTS(text=bot_message)
44
- myobj.save("temp.mp3")
45
-
46
- dir = os.getcwd()
47
- new_path = os.path.join(dir, "temp.mp3")
48
-
49
- return new_path
50
-
51
-
52
-
53
-
54
  with gr.Row():
55
  with gr.Column():
56
  user_audio = gr.Audio(source="microphone", type="filepath", label="Input Phrase")
 
6
 
7
  openai.api_key = os.environ["OPEN_AI_KEY"]
8
 
9
+ def transcribe(audio):
 
 
 
 
 
 
10
  audio_file = open(audio, "rb")
11
  # Call the transcribe method with the file-like object
12
  transcript = openai.Audio.transcribe("whisper-1", audio_file)
13
 
14
  return transcript["text"]
15
 
16
+ def giveVoice(bot_message):
17
+ myobj = gTTS(text=bot_message)
18
+ myobj.save("temp.mp3")
19
 
20
+ dir = os.getcwd()
21
+ new_path = os.path.join(dir, "temp.mp3")
22
+
23
+ return new_path
24
+
25
+
26
+ with gr.Blocks() as demo:
27
+ messages = gr.State(value=[{"role": "system", "content": "You are a therapist. Respond in less than 5 sentences."}])
28
+
29
+ def botResponse(user_input, messages):
30
  messages.append({"role": "user", "content": user_input})
31
  response = openai.ChatCompletion.create(
32
  model="gpt-3.5-turbo",
 
43
 
44
  return chat_transcript
45
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  with gr.Row():
47
  with gr.Column():
48
  user_audio = gr.Audio(source="microphone", type="filepath", label="Input Phrase")