固定端口号
This commit is contained in:
57
.__test.py
Normal file
57
.__test.py
Normal file
@ -0,0 +1,57 @@
|
||||
#! .\venv\
|
||||
# encoding: utf-8
|
||||
# @Time : 2023/4/19
|
||||
# @Author : Spike
|
||||
# @Descr :
|
||||
import gradio as gr
|
||||
|
||||
with gr.Blocks() as demo: # 绘制一个块对象,在此基础上可以使用Row、Column、Tab、Box等等布局元素
|
||||
gr.Markdown(f"<h1 align=\"center\">我是Bolcks</h1>")
|
||||
with gr.Row():
|
||||
with gr.Column(scale=100): # 组件绘制在布局元素下,则会根据布局元素的规定展示
|
||||
gr.Markdown('# 这里是列1')
|
||||
chatbot = gr.Chatbot().style(height=400)
|
||||
status = gr.Markdown()
|
||||
|
||||
with gr.Column(scale=50):
|
||||
gr.Markdown('# 这里是列2')
|
||||
i_say = gr.Textbox()
|
||||
submit = gr.Button(value='submit', variant='primary')
|
||||
with gr.Row():
|
||||
you_say = gr.Textbox(show_label=False, placeholder='没有任何用的输出框')
|
||||
Noo = gr.Button(value='没有任何用的按钮')
|
||||
|
||||
|
||||
def respond(say, chat_history):
|
||||
import random
|
||||
bot_message = random.choice(["How are you?", "I love you", "I'm very hungry"])
|
||||
chat_history.append((say, bot_message))
|
||||
return "我要开始胡说了", chat_history
|
||||
|
||||
# 注册函数 fn=要注册的函数, input=函数接收的参数, outputs=函数处理后返回接收的组件
|
||||
submit.click(fn=respond, inputs=[i_say, chatbot], outputs=[status, chatbot])
|
||||
|
||||
demo.launch()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
12
.gitignore
vendored
12
.gitignore
vendored
@ -111,7 +111,8 @@ env/
|
||||
venv/
|
||||
ENV/
|
||||
env.bak/
|
||||
venv.bak/
|
||||
venv.bak/
|
||||
.DS_Store
|
||||
|
||||
# Spyder project settings
|
||||
.spyderproject
|
||||
@ -127,13 +128,10 @@ venv.bak/
|
||||
.mypy_cache/
|
||||
.dmypy.json
|
||||
dmypy.json
|
||||
|
||||
# Pyre type checker
|
||||
.pyre/
|
||||
|
||||
.vscode
|
||||
.idea
|
||||
|
||||
history
|
||||
ssr_conf
|
||||
config_private.py
|
||||
@ -148,7 +146,5 @@ crazy_functions/test_project/pdf_and_word
|
||||
crazy_fun
|
||||
ctions/test_samples
|
||||
crazy_functions/test_samples
|
||||
request_llm/jittorllms
|
||||
!prompt_users/.keep
|
||||
prompt_users/*
|
||||
.__test.py
|
||||
request_llm/jittorllms
|
||||
prompt_users/*
|
||||
23
__main__.py
23
__main__.py
@ -342,14 +342,6 @@ class ChatBot(ChatBotFrame):
|
||||
threading.Thread(target=auto_update, name="self-upgrade", daemon=True).start()
|
||||
# threading.Thread(target=warm_up_modules, name="warm-up", daemon=True).start()
|
||||
|
||||
def check_proxy_free(self):
|
||||
proxy_state = func_box.Shell(f'lsof -i :{PORT}').read()[1].splitlines()
|
||||
if proxy_state != ["", ""]:
|
||||
print('Kill Old Server')
|
||||
for i in proxy_state[1:]:
|
||||
func_box.Shell(f'kill -9 {i.split()[1]}').read()
|
||||
import time
|
||||
time.sleep(5)
|
||||
|
||||
def main(self):
|
||||
with gr.Blocks(title="Chatbot for KSO ", theme=set_theme, analytics_enabled=False, css=advanced_css) as demo:
|
||||
@ -391,9 +383,22 @@ class ChatBot(ChatBotFrame):
|
||||
# Start
|
||||
self.auto_opentab_delay()
|
||||
demo.queue(concurrency_count=CONCURRENT_COUNT).launch(server_name="0.0.0.0", server_port=PORT,
|
||||
auth=AUTHENTICATION)
|
||||
|
||||
auth=AUTHENTICATION)
|
||||
def check_proxy_free():
|
||||
proxy_state = func_box.Shell(f'lsof -i :{PORT}').read()[1].splitlines()
|
||||
if proxy_state != ["", ""]:
|
||||
print('Kill Old Server')
|
||||
for i in proxy_state[1:]:
|
||||
func_box.Shell(f'kill -9 {i.split()[1]}').read()
|
||||
import time
|
||||
time.sleep(5)
|
||||
|
||||
if __name__ == '__main__':
|
||||
# PORT = find_free_port() if WEB_PORT <= 0 else WEB_PORT
|
||||
PORT = 7891 if WEB_PORT <= 0 else WEB_PORT
|
||||
check_proxy_free()
|
||||
ChatBot().main()
|
||||
gr.close_all()
|
||||
check_proxy_free()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user