Yusin commited on
Commit
c39b876
1 Parent(s): 33461be

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -13
app.py CHANGED
@@ -7,34 +7,41 @@ default_lang = "en"
7
  #import whisper
8
  #whisper_model = whisper.load_model("small")
9
  whisper = gr.Interface.load(name="spaces/sanchit-gandhi/whisper-large-v2")
10
- chatgpt = gr.Blocks.load(name="spaces/fffiloni/whisper-to-chatGPT")
11
  import os
12
- session_token = os.environ.get('SessionToken')
13
- conversation_id = os.environ.get('conversation_id')
14
  # ChatGPT
15
- from revChatGPT.ChatGPT import Chatbot
16
  #chatbot = Chatbot({"session_token": session_token}) # You can start a custom conversation
17
 
18
  title = "Speech to ChatGPT to Speech"
19
  #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
  #badge = "https://visitor-badge-reloaded.herokuapp.com/badge?page_id=neongeckocom.neon-tts-plugin-coqui"
21
-
22
  coquiTTS = CoquiTTS()
23
-
24
-
 
25
 
26
  # ChatGPT
27
  def chat_hf(audio, custom_token, language):
28
- output = chatgpt(audio, "transcribe", fn_index=0)
29
- whisper_text, gpt_response = output[0], output[1]
30
- '''
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,7 +60,7 @@ def chat_hf(audio, custom_token, language):
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})
 
7
  #import whisper
8
  #whisper_model = whisper.load_model("small")
9
  whisper = gr.Interface.load(name="spaces/sanchit-gandhi/whisper-large-v2")
10
+ #chatgpt = gr.Blocks.load(name="spaces/fffiloni/whisper-to-chatGPT")
11
  import os
12
+ import requests
13
+ #session_token = os.environ.get('SessionToken')
14
  # ChatGPT
15
+ #from revChatGPT.ChatGPT import Chatbot
16
  #chatbot = Chatbot({"session_token": session_token}) # You can start a custom conversation
17
 
18
  title = "Speech to ChatGPT to Speech"
19
  #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
  #badge = "https://visitor-badge-reloaded.herokuapp.com/badge?page_id=neongeckocom.neon-tts-plugin-coqui"
 
21
  coquiTTS = CoquiTTS()
22
+ chat_id = {'conversation_id': None, 'parent_id': None}
23
+ proxy = {'https': 'http://10.236.250.208'}
24
+ headers = {'Authorization': 'yusin'}
25
 
26
  # ChatGPT
27
  def chat_hf(audio, custom_token, language):
28
+ #output = chatgpt(audio, "transcribe", fn_index=0)
29
+ #whisper_text, gpt_response = output[0], output[1]
 
30
  try:
31
  whisper_text = translate(audio)
32
  if whisper_text == "ERROR: You have to either use the microphone or upload an audio file":
33
  gpt_response = "MISSING AUDIO: Record your voice by clicking the microphone button, do not forget to stop recording before sending your message ;)"
34
  else:
35
+ #gpt_response = chatbot.ask(whisper_text, conversation_id=conversation_id, parent_id=None)
36
+ if chat_id['conversation_id'] != None:
37
+ data = {"content": whisper_text, "conversation_id": chat_id['conversation_id'], "parent_id": chat_id['parent_id']}
38
+ else:
39
+ data = {"content": whisper_text}
40
+ response = requests.post('http://192.168.163.215:7788/api/ask', headers=headers, json=data, proxies=proxy)
41
+ chat_id['parent_id'] = response.json()["response_id"]
42
+ chat_id['conversation_id'] = response.json()["conversation_id"]
43
+ gpt_response = response.json()["content"]
44
+
45
  #whisper_text = translate(audio)
46
  #api = ChatGPT(session_token)
47
  #resp = api.send_message(whisper_text)
 
60
  #api.refresh_auth() # refresh the authorization token
61
  #api.reset_conversation() # reset the conversation
62
  #gpt_response = resp['message']
63
+
64
  # to voice
65
  with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
66
  coquiTTS.get_tts(gpt_response, fp, speaker = {"language" : language})