Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,26 @@ from common.log import logger
|
|
7 |
from plugins import *
|
8 |
import signal
|
9 |
import sys
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
def sigterm_handler_wrap(_signo):
|
12 |
old_handler = signal.getsignal(_signo)
|
@@ -42,4 +62,20 @@ def run():
|
|
42 |
logger.exception(e)
|
43 |
|
44 |
if __name__ == '__main__':
|
45 |
-
run()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
from plugins import *
|
8 |
import signal
|
9 |
import sys
|
10 |
+
import gradio as gr
|
11 |
+
from io import BytesIO
|
12 |
+
from PIL import Image
|
13 |
+
from concurrent.futures import ThreadPoolExecutor
|
14 |
+
thread_pool = ThreadPoolExecutor(max_workers=8)
|
15 |
+
|
16 |
+
def getImage(bytes):
|
17 |
+
bytes_stream = BytesIO(bytes)
|
18 |
+
image = Image.open(bytes_stream)
|
19 |
+
return image
|
20 |
+
|
21 |
+
def getLoginUrl():
|
22 |
+
# load config
|
23 |
+
config.load_config()
|
24 |
+
# create channel
|
25 |
+
bot = channel_factory.create_channel("wx")
|
26 |
+
thread_pool.submit(bot.startup)
|
27 |
+
while (True):
|
28 |
+
if bot.getQrCode():
|
29 |
+
return getImage(bot.getQrCode())
|
30 |
|
31 |
def sigterm_handler_wrap(_signo):
|
32 |
old_handler = signal.getsignal(_signo)
|
|
|
62 |
logger.exception(e)
|
63 |
|
64 |
if __name__ == '__main__':
|
65 |
+
#run()
|
66 |
+
try:
|
67 |
+
|
68 |
+
with gr.Blocks() as demo:
|
69 |
+
with gr.Row():
|
70 |
+
with gr.Column():
|
71 |
+
btn = gr.Button(value="生成二维码")
|
72 |
+
with gr.Column():
|
73 |
+
outputs=[gr.Pil()]
|
74 |
+
btn.click(getLoginUrl, outputs=outputs)
|
75 |
+
|
76 |
+
demo.launch()
|
77 |
+
|
78 |
+
|
79 |
+
except Exception as e:
|
80 |
+
logger.error("App startup failed!")
|
81 |
+
logger.exception(e)
|