Update main.py
Browse files
main.py
CHANGED
|
@@ -12,6 +12,7 @@ REPO_PATH = "/root/modelscope"
|
|
| 12 |
|
| 13 |
FRP_VERSION = "0.69.0"
|
| 14 |
CURRENT_DIR = REPO_PATH
|
|
|
|
| 15 |
|
| 16 |
|
| 17 |
def clone_repository():
|
|
@@ -102,7 +103,7 @@ def execute_shell_command(command):
|
|
| 102 |
return f"执行命令失败: {e}"
|
| 103 |
|
| 104 |
|
| 105 |
-
def
|
| 106 |
if input_text.startswith("cmd_run "):
|
| 107 |
command = input_text[len("cmd_run "):].strip()
|
| 108 |
return execute_shell_command(command)
|
|
@@ -147,6 +148,24 @@ def api_call(input_text, model="internlm2.5-latest", temperature=0.8, top_p=0.9,
|
|
| 147 |
return f"API 请求失败: {e}"
|
| 148 |
|
| 149 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
def create_frpc_toml():
|
| 151 |
os.makedirs(REPO_PATH, exist_ok=True)
|
| 152 |
|
|
@@ -389,7 +408,9 @@ def start_gradio():
|
|
| 389 |
label="生成回复数量"
|
| 390 |
)
|
| 391 |
|
| 392 |
-
|
|
|
|
|
|
|
| 393 |
|
| 394 |
output_box = gr.Textbox(
|
| 395 |
label="回复",
|
|
@@ -409,6 +430,18 @@ def start_gradio():
|
|
| 409 |
outputs=output_box
|
| 410 |
)
|
| 411 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 412 |
print("Gradio 正在启动。")
|
| 413 |
|
| 414 |
demo.launch(
|
|
|
|
| 12 |
|
| 13 |
FRP_VERSION = "0.69.0"
|
| 14 |
CURRENT_DIR = REPO_PATH
|
| 15 |
+
LAST_OUTPUT = ""
|
| 16 |
|
| 17 |
|
| 18 |
def clone_repository():
|
|
|
|
| 103 |
return f"执行命令失败: {e}"
|
| 104 |
|
| 105 |
|
| 106 |
+
def _api_call_impl(input_text, model="internlm2.5-latest", temperature=0.8, top_p=0.9, n=1):
|
| 107 |
if input_text.startswith("cmd_run "):
|
| 108 |
command = input_text[len("cmd_run "):].strip()
|
| 109 |
return execute_shell_command(command)
|
|
|
|
| 148 |
return f"API 请求失败: {e}"
|
| 149 |
|
| 150 |
|
| 151 |
+
def api_call(input_text, model="internlm2.5-latest", temperature=0.8, top_p=0.9, n=1):
|
| 152 |
+
global LAST_OUTPUT
|
| 153 |
+
|
| 154 |
+
LAST_OUTPUT = _api_call_impl(
|
| 155 |
+
input_text,
|
| 156 |
+
model,
|
| 157 |
+
temperature,
|
| 158 |
+
top_p,
|
| 159 |
+
n
|
| 160 |
+
)
|
| 161 |
+
|
| 162 |
+
return LAST_OUTPUT
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
def refresh_frontend():
|
| 166 |
+
return LAST_OUTPUT
|
| 167 |
+
|
| 168 |
+
|
| 169 |
def create_frpc_toml():
|
| 170 |
os.makedirs(REPO_PATH, exist_ok=True)
|
| 171 |
|
|
|
|
| 408 |
label="生成回复数量"
|
| 409 |
)
|
| 410 |
|
| 411 |
+
with gr.Row():
|
| 412 |
+
send_button = gr.Button("发送", variant="primary")
|
| 413 |
+
refresh_button = gr.Button("刷新前端")
|
| 414 |
|
| 415 |
output_box = gr.Textbox(
|
| 416 |
label="回复",
|
|
|
|
| 430 |
outputs=output_box
|
| 431 |
)
|
| 432 |
|
| 433 |
+
refresh_button.click(
|
| 434 |
+
refresh_frontend,
|
| 435 |
+
outputs=output_box
|
| 436 |
+
)
|
| 437 |
+
|
| 438 |
+
timer = gr.Timer(5)
|
| 439 |
+
|
| 440 |
+
timer.tick(
|
| 441 |
+
refresh_frontend,
|
| 442 |
+
outputs=output_box
|
| 443 |
+
)
|
| 444 |
+
|
| 445 |
print("Gradio 正在启动。")
|
| 446 |
|
| 447 |
demo.launch(
|