Spaces:
Runtime error
Runtime error
Commit
·
75461b8
1
Parent(s):
9c9abc5
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,45 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
-
def
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from pawansapi import PyGPT
|
3 |
|
4 |
+
async def start_bot(chat_gpt):
|
5 |
+
try:
|
6 |
+
await chat_gpt.connect()
|
7 |
+
except ConnectionError as e:
|
8 |
+
print("socketio.exceptions:", str(e))
|
9 |
+
return "socketio.exceptions.ConnectionError"
|
10 |
+
await chat_gpt.wait_for_ready()
|
11 |
|
12 |
+
async def greet():
|
13 |
+
|
14 |
+
chat_gpt = bots_config[k]['chat_gpt']
|
15 |
+
try:
|
16 |
+
if not chat_gpt.auth or not chat_gpt.validate_token(chat_gpt.auth):
|
17 |
+
await chat_gpt.get_tokens()
|
18 |
+
except TimeoutError as e:
|
19 |
+
return {"status": 404, "reply": "validate_token TimeoutError"}
|
20 |
+
|
21 |
+
try:
|
22 |
+
reply = await chat_gpt.ask(query_data)
|
23 |
+
except TimeoutError as e:
|
24 |
+
return {"status": 404, "reply": "ask TimeoutError"}
|
25 |
+
|
26 |
+
return reply
|
27 |
+
|
28 |
+
def get_session_id(bot_id):
|
29 |
+
|
30 |
+
return requests.post(url, data = {"bot_id":bot_id})
|
31 |
+
|
32 |
+
if __name__ == "__main__":
|
33 |
+
|
34 |
+
bots_config = {"b0":{}, "b1":{}, "b2":{}}
|
35 |
+
|
36 |
+
for k, v in bots_config.items():
|
37 |
+
bots_config[k]['chat_gpt'] = PyGPT(get_session_id(k))
|
38 |
+
await start_bot(bots_config[k]['chat_gpt'])
|
39 |
+
|
40 |
+
iface = gr.Interface(fn=await greet, inputs=["text"], outputs="text")
|
41 |
+
iface.launch()
|
42 |
+
|
43 |
+
for k, v in bots_config.items():
|
44 |
+
print(k, 'disconnect')
|
45 |
+
await bots_config[k]['chat_gpt'].disconnect()
|