Yusin commited on
Commit
93641fd
·
1 Parent(s): 4c752bf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -24
app.py CHANGED
@@ -10,16 +10,13 @@ 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 json
13
- import requests
14
- import requests
15
- from urllib3.exceptions import InsecureRequestWarning
16
- # Suppress the warnings from urllib3
17
- requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)
18
- #session_token = os.environ.get('SessionToken')
19
- api_endpoint = os.environ.get('API_EndPoint')
20
  # ChatGPT
21
  #from revChatGPT.ChatGPT import Chatbot
22
  #chatbot = Chatbot({"session_token": session_token}) # You can start a custom conversation
 
 
23
 
24
  title = "Speech to ChatGPT to Speech"
25
  #info = "more info at [Neon Coqui TTS Plugin](https://github.com/NeonGeckoCom/neon-tts-plugin-coqui), [Coqui TTS](https://github.com/coqui-ai/TTS)"
@@ -28,20 +25,13 @@ coquiTTS = CoquiTTS()
28
  chat_id = {'conversation_id': None, 'parent_id': None}
29
  headers = {'Authorization': 'yusin'}
30
 
31
- import socket
32
-
33
- def detect_port(ip,port):
34
- """检测ip上的端口是否开放
35
- """
36
- s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
37
- try:
38
- s.connect((ip,int(port)))
39
- s.shutdown(2)
40
- print('{0} is open'.format(port))
41
- return True
42
- except:
43
- print('{0} is close'.format(port))
44
- return False
45
 
46
  # ChatGPT
47
  def chat_hf(audio, custom_token, language):
@@ -53,7 +43,7 @@ def chat_hf(audio, custom_token, language):
53
  gpt_response = "MISSING AUDIO: Record your voice by clicking the microphone button, do not forget to stop recording before sending your message ;)"
54
  else:
55
  #gpt_response = chatbot.ask(whisper_text, conversation_id=conversation_id, parent_id=None)
56
- print(whisper_text)
57
  #if chat_id['conversation_id'] != None:
58
  # data = {"content": whisper_text, "conversation_id": chat_id['conversation_id'], "parent_id": chat_id['parent_id']}
59
  #else:
@@ -66,8 +56,8 @@ def chat_hf(audio, custom_token, language):
66
  #chat_id['parent_id'] = response.json()["response_id"]
67
  #chat_id['conversation_id'] = response.json()["conversation_id"]
68
  #gpt_response = response.json()["content"]
69
- response = requests.get('https://api.pawan.krd/chat/gpt?text=' + whisper_text + '&cache=false', verify=False, timeout=5)
70
- print(response.text)
71
 
72
  #whisper_text = translate(audio)
73
  #api = ChatGPT(session_token)
 
10
  #chatgpt = gr.Blocks.load(name="spaces/fffiloni/whisper-to-chatGPT")
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
  chat_id = {'conversation_id': None, 'parent_id': None}
26
  headers = {'Authorization': 'yusin'}
27
 
28
+ async def chat_gpt_ask(prompt):
29
+ chat_gpt = PyGPT(session_token)
30
+ await chat_gpt.connect()
31
+ await chat_gpt.wait_for_ready()
32
+ answer = await chat_gpt.ask(prompt)
33
+ print(answer)
34
+ await chat_gpt.disconnect()
 
 
 
 
 
 
 
35
 
36
  # ChatGPT
37
  def chat_hf(audio, custom_token, language):
 
43
  gpt_response = "MISSING AUDIO: Record your voice by clicking the microphone button, do not forget to stop recording before sending your message ;)"
44
  else:
45
  #gpt_response = chatbot.ask(whisper_text, conversation_id=conversation_id, parent_id=None)
46
+ gpt_response = asyncio.run(chat_gpt_ask(whisper_text))
47
  #if chat_id['conversation_id'] != None:
48
  # data = {"content": whisper_text, "conversation_id": chat_id['conversation_id'], "parent_id": chat_id['parent_id']}
49
  #else:
 
56
  #chat_id['parent_id'] = response.json()["response_id"]
57
  #chat_id['conversation_id'] = response.json()["conversation_id"]
58
  #gpt_response = response.json()["content"]
59
+ #response = requests.get('https://api.pawan.krd/chat/gpt?text=' + whisper_text + '&cache=false', verify=False, timeout=5)
60
+ #print(response.text)
61
 
62
  #whisper_text = translate(audio)
63
  #api = ChatGPT(session_token)