Yusin commited on
Commit
08e9f82
1 Parent(s): 4cd7911

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -4
app.py CHANGED
@@ -10,8 +10,11 @@ whisper = gr.Interface.load(name="spaces/sanchit-gandhi/whisper-large-v2")
10
  chatgpt = gr.Blocks.load(name="spaces/seawolf2357/chatgptclone")
11
  import os
12
  import json
 
13
  #session_token = os.environ.get('SessionToken')
14
- #api_endpoint = os.environ.get('API_EndPoint')
 
 
15
 
16
  title = "Speech to ChatGPT to Speech"
17
  #info = "more info at [Neon Coqui TTS Plugin](https://github.com/NeonGeckoCom/neon-tts-plugin-coqui), [Coqui TTS](https://github.com/coqui-ai/TTS)"
@@ -26,9 +29,10 @@ def chat_hf(audio, custom_token, language):
26
  if whisper_text == "ERROR: You have to either use the microphone or upload an audio file":
27
  gpt_response = "MISSING AUDIO: Record your voice by clicking the microphone button, do not forget to stop recording before sending your message ;)"
28
  else:
29
- gpt_response = chatgpt(whisper_text, [], fn_index=0)
30
- print(gpt_response)
31
- gpt_response = gpt_response[0]
 
32
 
33
  except:
34
  whisper_text = translate(audio)
@@ -78,6 +82,21 @@ def translate(audio):
78
  return text_result
79
 
80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  with gr.Blocks() as blocks:
82
  gr.Markdown("<h1 style='text-align: center; margin-bottom: 1rem'>"
83
  + title
 
10
  chatgpt = gr.Blocks.load(name="spaces/seawolf2357/chatgptclone")
11
  import os
12
  import json
13
+ import openai
14
  #session_token = os.environ.get('SessionToken')
15
+ api_key = os.environ.get('api_key')
16
+ #if you have OpenAI API key as a string, enable the below
17
+ openai.api_key = api_key
18
 
19
  title = "Speech to ChatGPT to Speech"
20
  #info = "more info at [Neon Coqui TTS Plugin](https://github.com/NeonGeckoCom/neon-tts-plugin-coqui), [Coqui TTS](https://github.com/coqui-ai/TTS)"
 
29
  if whisper_text == "ERROR: You have to either use the microphone or upload an audio file":
30
  gpt_response = "MISSING AUDIO: Record your voice by clicking the microphone button, do not forget to stop recording before sending your message ;)"
31
  else:
32
+ #gpt_response = chatgpt(whisper_text, [], fn_index=0)
33
+ #print(gpt_response)
34
+ #gpt_response = gpt_response[0]
35
+ gpt_response = openai_create(whisper_text)
36
 
37
  except:
38
  whisper_text = translate(audio)
 
82
  return text_result
83
 
84
 
85
+ def openai_create(prompt):
86
+
87
+ response = openai.Completion.create(
88
+ model="text-davinci-003",
89
+ prompt=prompt,
90
+ temperature=0.9,
91
+ max_tokens=150,
92
+ top_p=1,
93
+ frequency_penalty=0,
94
+ presence_penalty=0.6,
95
+ stop=[" Human:", " AI:"]
96
+ )
97
+
98
+ return response.choices[0].text
99
+
100
  with gr.Blocks() as blocks:
101
  gr.Markdown("<h1 style='text-align: center; margin-bottom: 1rem'>"
102
  + title