Files changed (1) hide show
  1. app.py +28 -12
app.py CHANGED
@@ -5,12 +5,13 @@ LANGUAGES = list(CoquiTTS.langs.keys())
5
  default_lang = "en"
6
 
7
  # ChatGPT
8
- from pyChatGPT import ChatGPT
9
  #import whisper
10
  #whisper_model = whisper.load_model("small")
11
  whisper = gr.Interface.load(name="spaces/sanchit-gandhi/whisper-large-v2")
12
  import os
13
- session_token = os.environ.get('SessionToken')
 
14
 
15
  title = "Speech to ChatGPT to Speech"
16
  #info = "more info at [Neon Coqui TTS Plugin](https://github.com/NeonGeckoCom/neon-tts-plugin-coqui), [Coqui TTS](https://github.com/coqui-ai/TTS)"
@@ -18,26 +19,41 @@ title = "Speech to ChatGPT to Speech"
18
 
19
  coquiTTS = CoquiTTS()
20
 
 
 
 
 
 
 
 
21
 
 
22
  # ChatGPT
23
  def chat_hf(audio, custom_token, language):
24
  try:
25
  whisper_text = translate(audio)
26
- api = ChatGPT(session_token)
27
- resp = api.send_message(whisper_text)
 
 
 
 
 
28
 
29
- api.refresh_auth() # refresh the authorization token
30
- api.reset_conversation() # reset the conversation
31
- gpt_response = resp['message']
32
 
33
  except:
34
  whisper_text = translate(audio)
35
- api = ChatGPT(custom_token)
36
- resp = api.send_message(whisper_text)
 
 
37
 
38
- api.refresh_auth() # refresh the authorization token
39
- api.reset_conversation() # reset the conversation
40
- gpt_response = resp['message']
41
 
42
  # to voice
43
  with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
 
5
  default_lang = "en"
6
 
7
  # ChatGPT
8
+ #from pyChatGPT import ChatGPT
9
  #import whisper
10
  #whisper_model = whisper.load_model("small")
11
  whisper = gr.Interface.load(name="spaces/sanchit-gandhi/whisper-large-v2")
12
  import os
13
+ #session_token = os.environ.get('SessionToken')
14
+ api = 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)"
 
19
 
20
  coquiTTS = CoquiTTS()
21
 
22
+ def call_api(message):
23
+ response = requests.get(f'{api}?q={message}')
24
+ if response.status_code == 200:
25
+
26
+ return str(response.text).split('\n', 2)[2]
27
+ else:
28
+ return """Sorry, I'm quite busy right now, but please try again later :)"""
29
 
30
+
31
  # ChatGPT
32
  def chat_hf(audio, custom_token, language):
33
  try:
34
  whisper_text = translate(audio)
35
+ if whisper_text == "ERROR: You have to either use the microphone or upload an audio file":
36
+ gpt_response = "MISSING AUDIO: Record your voice by clicking the microphone button, do not forget to stop recording before sending your message ;)"
37
+ else:
38
+ gpt_response = call_api(whisper_text)
39
+ #whisper_text = translate(audio)
40
+ #api = ChatGPT(session_token)
41
+ #resp = api.send_message(whisper_text)
42
 
43
+ #api.refresh_auth() # refresh the authorization token
44
+ #api.reset_conversation() # reset the conversation
45
+ #gpt_response = resp['message']
46
 
47
  except:
48
  whisper_text = translate(audio)
49
+ gpt_response = """Sorry, I'm quite busy right now, but please try again later :)"""
50
+ #whisper_text = translate(audio)
51
+ #api = ChatGPT(custom_token)
52
+ #resp = api.send_message(whisper_text)
53
 
54
+ #api.refresh_auth() # refresh the authorization token
55
+ #api.reset_conversation() # reset the conversation
56
+ #gpt_response = resp['message']
57
 
58
  # to voice
59
  with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp: