Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -3,142 +3,35 @@ import gradio as gr
|
|
3 |
from neon_tts_plugin_coqui import CoquiTTS
|
4 |
LANGUAGES = list(CoquiTTS.langs.keys())
|
5 |
default_lang = "en"
|
6 |
-
import telnetlib
|
7 |
#import whisper
|
8 |
#whisper_model = whisper.load_model("small")
|
9 |
-
|
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 |
-
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)"
|
28 |
#badge = "https://visitor-badge-reloaded.herokuapp.com/badge?page_id=neongeckocom.neon-tts-plugin-coqui"
|
29 |
coquiTTS = CoquiTTS()
|
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 |
-
print(session_token, bypass_node)
|
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 |
-
print(response)
|
49 |
-
return response['answer']
|
50 |
-
|
51 |
-
|
52 |
|
53 |
-
def sync_main(prompt):
|
54 |
-
chat = Chatbot(session_token, bypass_node)
|
55 |
-
# Create loop
|
56 |
-
loop = asyncio.new_event_loop()
|
57 |
-
# Set
|
58 |
-
asyncio.set_event_loop(loop)
|
59 |
-
# Run
|
60 |
-
loop.run_until_complete(chat.wait_for_ready())
|
61 |
-
while True:
|
62 |
-
response = loop.run_until_complete(chat.ask(prompt))
|
63 |
-
print(f"\nBot: {response['answer']}\n")
|
64 |
-
# Close sockets
|
65 |
-
chat.close()
|
66 |
-
# stop asyncio event loop
|
67 |
-
loop.stop()
|
68 |
-
# exit
|
69 |
-
#sys.exit(0)
|
70 |
-
print(response)
|
71 |
-
return response['answer']
|
72 |
-
|
73 |
-
###########################################
|
74 |
-
parser = argparse.ArgumentParser()
|
75 |
-
parser.add_argument('--session_token', type=str, default=None)
|
76 |
-
parser.add_argument('--bypass_node', type=str, default="https://gpt.pawan.krd")
|
77 |
-
parser.add_argument('--async_mode', action='store_true')
|
78 |
-
args = parser.parse_args()
|
79 |
-
args.session_token = session_token
|
80 |
-
##########################################
|
81 |
-
|
82 |
-
async def chat_gpt_ask(prompt):
|
83 |
-
print(session_token)
|
84 |
-
chat_gpt = PyGPT(session_token)
|
85 |
-
await chat_gpt.connect()
|
86 |
-
await chat_gpt.wait_for_ready()
|
87 |
-
print(prompt)
|
88 |
-
answer = await chat_gpt.ask(prompt)
|
89 |
-
print(answer)
|
90 |
-
await chat_gpt.disconnect()
|
91 |
|
92 |
# ChatGPT
|
93 |
def chat_hf(audio, custom_token, language):
|
94 |
-
output = chatgpt(audio, "transcribe", fn_index=0)
|
95 |
-
whisper_text, gpt_response = output[0], output[1]
|
96 |
-
#whisper_text = translate(audio)
|
97 |
-
#gpt_response = asyncio.run(async_main(whisper_text))
|
98 |
-
'''
|
99 |
try:
|
100 |
whisper_text = translate(audio)
|
101 |
if whisper_text == "ERROR: You have to either use the microphone or upload an audio file":
|
102 |
gpt_response = "MISSING AUDIO: Record your voice by clicking the microphone button, do not forget to stop recording before sending your message ;)"
|
103 |
else:
|
104 |
-
|
105 |
-
#gpt_response = asyncio.run(chat_gpt_ask(whisper_text))
|
106 |
-
gpt_response = asyncio.run(async_main(whisper_text))
|
107 |
-
#gpt_response = async_main(whisper_text)
|
108 |
-
#if chat_id['conversation_id'] != None:
|
109 |
-
# data = {"content": whisper_text, "conversation_id": chat_id['conversation_id'], "parent_id": chat_id['parent_id']}
|
110 |
-
#else:
|
111 |
-
# data = {"content": whisper_text}
|
112 |
-
#print(data)
|
113 |
-
#res = requests.get('http://myip.ipip.net', timeout=5).text
|
114 |
-
#print(res)
|
115 |
-
#response = requests.post('api_endpoint', headers=headers, json=data, verify=False, timeout=5)
|
116 |
-
#print('this is my answear', response.text)
|
117 |
-
#chat_id['parent_id'] = response.json()["response_id"]
|
118 |
-
#chat_id['conversation_id'] = response.json()["conversation_id"]
|
119 |
-
#gpt_response = response.json()["content"]
|
120 |
-
#response = requests.get('https://api.pawan.krd/chat/gpt?text=' + whisper_text + '&cache=false', verify=False, timeout=5)
|
121 |
-
#print(response.text)
|
122 |
-
|
123 |
-
#whisper_text = translate(audio)
|
124 |
-
#api = ChatGPT(session_token)
|
125 |
-
#resp = api.send_message(whisper_text)
|
126 |
-
|
127 |
-
#api.refresh_auth() # refresh the authorization token
|
128 |
-
#api.reset_conversation() # reset the conversation
|
129 |
-
#gpt_response = resp['message']
|
130 |
|
131 |
except:
|
132 |
whisper_text = translate(audio)
|
133 |
gpt_response = """Sorry, I'm quite busy right now, but please try again later :)"""
|
134 |
-
#whisper_text = translate(audio)
|
135 |
-
#api = ChatGPT(custom_token)
|
136 |
-
#resp = api.send_message(whisper_text)
|
137 |
|
138 |
-
#api.refresh_auth() # refresh the authorization token
|
139 |
-
#api.reset_conversation() # reset the conversation
|
140 |
-
#gpt_response = resp['message']
|
141 |
-
'''
|
142 |
# to voice
|
143 |
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
|
144 |
coquiTTS.get_tts(gpt_response, fp, speaker = {"language" : language})
|
|
|
3 |
from neon_tts_plugin_coqui import CoquiTTS
|
4 |
LANGUAGES = list(CoquiTTS.langs.keys())
|
5 |
default_lang = "en"
|
|
|
6 |
#import whisper
|
7 |
#whisper_model = whisper.load_model("small")
|
8 |
+
whisper = gr.Interface.load(name="spaces/sanchit-gandhi/whisper-large-v2")
|
9 |
+
#chatgpt = gr.Blocks.load(name="spaces/fffiloni/whisper-to-chatGPT")
|
10 |
+
chatgpt = gr.Blocks.load(name="spaces/seawolf2357/chatgptclone")
|
11 |
import os
|
12 |
import json
|
13 |
+
#session_token = os.environ.get('SessionToken')
|
|
|
14 |
#api_endpoint = 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)"
|
18 |
#badge = "https://visitor-badge-reloaded.herokuapp.com/badge?page_id=neongeckocom.neon-tts-plugin-coqui"
|
19 |
coquiTTS = CoquiTTS()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
# ChatGPT
|
23 |
def chat_hf(audio, custom_token, language):
|
|
|
|
|
|
|
|
|
|
|
24 |
try:
|
25 |
whisper_text = translate(audio)
|
26 |
if whisper_text == "ERROR: You have to either use the microphone or upload an audio file":
|
27 |
gpt_response = "MISSING AUDIO: Record your voice by clicking the microphone button, do not forget to stop recording before sending your message ;)"
|
28 |
else:
|
29 |
+
gpt_response = chatgpt(whisper_text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
except:
|
32 |
whisper_text = translate(audio)
|
33 |
gpt_response = """Sorry, I'm quite busy right now, but please try again later :)"""
|
|
|
|
|
|
|
34 |
|
|
|
|
|
|
|
|
|
35 |
# to voice
|
36 |
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
|
37 |
coquiTTS.get_tts(gpt_response, fp, speaker = {"language" : language})
|