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