Improve the way to open webbrowser

This commit is contained in:
Chuan Hu 2023-03-28 22:47:30 +08:00 committed by GitHub
parent 5a6877f9fa
commit 46eba1f399
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

12
main.py
View File

@ -89,15 +89,5 @@ with gr.Blocks(theme=set_theme, analytics_enabled=False) as demo:
except: pass except: pass
# 延迟函数, 做一些准备工作, 最后尝试打开浏览器
def auto_opentab_delay():
import threading, webbrowser, time
print(f"URL http://localhost:{PORT}")
def open(): time.sleep(2)
webbrowser.open_new_tab(f'http://localhost:{PORT}')
t = threading.Thread(target=open)
t.daemon = True; t.start()
auto_opentab_delay()
demo.title = "ChatGPT 学术优化" demo.title = "ChatGPT 学术优化"
demo.queue().launch(server_name="0.0.0.0", share=True, server_port=PORT) demo.queue().launch(server_name="0.0.0.0", share=True, server_port=PORT, inbrowser=True)