Yusin commited on
Commit
ca70bdc
1 Parent(s): a53427f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -1
app.py CHANGED
@@ -11,12 +11,17 @@ whisper = gr.Interface.load(name="spaces/sanchit-gandhi/whisper-large-v2")
11
  import os
12
  import json
13
  session_token = os.environ.get('SessionToken')
 
14
  #api_endpoint = os.environ.get('API_EndPoint')
15
  # ChatGPT
16
  #from revChatGPT.ChatGPT import Chatbot
17
  #chatbot = Chatbot({"session_token": session_token}) # You can start a custom conversation
18
  import asyncio
19
  from pygpt import PyGPT
 
 
 
 
20
 
21
  title = "Speech to ChatGPT to Speech"
22
  #info = "more info at [Neon Coqui TTS Plugin](https://github.com/NeonGeckoCom/neon-tts-plugin-coqui), [Coqui TTS](https://github.com/coqui-ai/TTS)"
@@ -25,6 +30,53 @@ coquiTTS = CoquiTTS()
25
  chat_id = {'conversation_id': None, 'parent_id': None}
26
  headers = {'Authorization': 'yusin'}
27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  async def chat_gpt_ask(prompt):
29
  print(session_token)
30
  chat_gpt = PyGPT(session_token)
@@ -45,7 +97,8 @@ def chat_hf(audio, custom_token, language):
45
  gpt_response = "MISSING AUDIO: Record your voice by clicking the microphone button, do not forget to stop recording before sending your message ;)"
46
  else:
47
  #gpt_response = chatbot.ask(whisper_text, conversation_id=conversation_id, parent_id=None)
48
- gpt_response = asyncio.run(chat_gpt_ask(whisper_text))
 
49
  #if chat_id['conversation_id'] != None:
50
  # data = {"content": whisper_text, "conversation_id": chat_id['conversation_id'], "parent_id": chat_id['parent_id']}
51
  #else:
 
11
  import os
12
  import json
13
  session_token = os.environ.get('SessionToken')
14
+ bypass_node = "https://gpt.pawan.krd"
15
  #api_endpoint = os.environ.get('API_EndPoint')
16
  # ChatGPT
17
  #from revChatGPT.ChatGPT import Chatbot
18
  #chatbot = Chatbot({"session_token": session_token}) # You can start a custom conversation
19
  import asyncio
20
  from pygpt import PyGPT
21
+ import argparse
22
+ import sys
23
+ import asyncio
24
+ from ChatGPT_lite.ChatGPT import Chatbot
25
 
26
  title = "Speech to ChatGPT to Speech"
27
  #info = "more info at [Neon Coqui TTS Plugin](https://github.com/NeonGeckoCom/neon-tts-plugin-coqui), [Coqui TTS](https://github.com/coqui-ai/TTS)"
 
30
  chat_id = {'conversation_id': None, 'parent_id': None}
31
  headers = {'Authorization': 'yusin'}
32
 
33
+ ##############################################################
34
+ async def async_main(prompt):
35
+ if session_token is None:
36
+ print("Please provide a session token")
37
+
38
+ chat = Chatbot(session_token, bypass_node)
39
+ await asyncio.gather(chat.wait_for_ready())
40
+
41
+ while True:
42
+ response = await chat.ask(prompt)
43
+ print(f"\nBot: {response['answer']}\n")
44
+ # Close sockets
45
+ chat.close()
46
+ # exit
47
+ #sys.exit(0)
48
+ return response['answer']
49
+
50
+
51
+
52
+ def sync_main(prompt):
53
+ chat = Chatbot(session_token, bypass_node)
54
+ # Create loop
55
+ loop = asyncio.new_event_loop()
56
+ # Set
57
+ asyncio.set_event_loop(loop)
58
+ # Run
59
+ loop.run_until_complete(chat.wait_for_ready())
60
+ while True:
61
+ response = loop.run_until_complete(chat.ask(prompt))
62
+ print(f"\nBot: {response['answer']}\n")
63
+ # Close sockets
64
+ chat.close()
65
+ # stop asyncio event loop
66
+ loop.stop()
67
+ # exit
68
+ #sys.exit(0)
69
+ return response['answer']
70
+
71
+ ###########################################
72
+ parser = argparse.ArgumentParser()
73
+ parser.add_argument('--session_token', type=str, default=None)
74
+ parser.add_argument('--bypass_node', type=str, default="https://gpt.pawan.krd")
75
+ parser.add_argument('--async_mode', action='store_true')
76
+ args = parser.parse_args()
77
+ args.session_token = session_token
78
+ ##########################################
79
+
80
  async def chat_gpt_ask(prompt):
81
  print(session_token)
82
  chat_gpt = PyGPT(session_token)
 
97
  gpt_response = "MISSING AUDIO: Record your voice by clicking the microphone button, do not forget to stop recording before sending your message ;)"
98
  else:
99
  #gpt_response = chatbot.ask(whisper_text, conversation_id=conversation_id, parent_id=None)
100
+ #gpt_response = asyncio.run(chat_gpt_ask(whisper_text))
101
+ gpt_response = asyncio.run(async_main(whisper_text))
102
  #if chat_id['conversation_id'] != None:
103
  # data = {"content": whisper_text, "conversation_id": chat_id['conversation_id'], "parent_id": chat_id['parent_id']}
104
  #else: