Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,23 +1,32 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
from llama_cpp import Llama
|
| 3 |
-
import os
|
| 4 |
-
|
| 5 |
-
model_path = os.getenv("MODEL_PATH", "/models/Qwen3_Medical_GRPO-i1-Q4_K_M.gguf")
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from llama_cpp import Llama
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
model_path = os.getenv("MODEL_PATH", "/models/Qwen3_Medical_GRPO-i1-Q4_K_M.gguf")
|
| 6 |
+
|
| 7 |
+
# 初始化模型
|
| 8 |
+
llm = Llama(model_path=model_path, n_ctx=4096, n_threads=8)
|
| 9 |
+
|
| 10 |
+
# 定义 system prompt
|
| 11 |
+
system_prompt = """You are given a problem.
|
| 12 |
+
Think about the problem and provide your working out.
|
| 13 |
+
Place it between <start_working_out> and <end_working_out>.
|
| 14 |
+
Then, provide your solution between <SOLUTION></SOLUTION>"""
|
| 15 |
+
|
| 16 |
+
def chat(user_input):
|
| 17 |
+
# 在用户输入末尾加上 <start_working_out>
|
| 18 |
+
prompt = system_prompt + "\n\nUser input: " + user_input + " <start_working_out>"
|
| 19 |
+
response = llm(prompt, max_tokens=2048, temperature=0.7)
|
| 20 |
+
return response["choices"][0]["text"]
|
| 21 |
+
|
| 22 |
+
with gr.Blocks() as demo:
|
| 23 |
+
gr.Markdown("# 🦙 GGUF Model Demo")
|
| 24 |
+
with gr.Row():
|
| 25 |
+
with gr.Column():
|
| 26 |
+
input_box = gr.Textbox(label="输入你的问题", placeholder="请输入问题...")
|
| 27 |
+
submit_btn = gr.Button("生成回答")
|
| 28 |
+
with gr.Column():
|
| 29 |
+
output_box = gr.Textbox(label="模型回答", lines=10)
|
| 30 |
+
submit_btn.click(fn=chat, inputs=input_box, outputs=output_box)
|
| 31 |
+
|
| 32 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|