Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from llama_cpp import Llama
|
3 |
+
|
4 |
+
# 初始化模型
|
5 |
+
MODEL_PATH = "models/qwen2.5-0.5b-instruct-q5_k_m.gguf"
|
6 |
+
|
7 |
+
llm = Llama(
|
8 |
+
model_path=MODEL_PATH,
|
9 |
+
n_ctx=2048,
|
10 |
+
n_gpu_layers=0,
|
11 |
+
)
|
12 |
+
|
13 |
+
def chat(user_input):
|
14 |
+
prompt = f"User: {user_input}\nAssistant: "
|
15 |
+
output = llm(
|
16 |
+
prompt=prompt,
|
17 |
+
temperature=0.7,
|
18 |
+
top_p=0.9,
|
19 |
+
max_tokens=100
|
20 |
+
)
|
21 |
+
response_text = output['choices'][0]['text'].strip()
|
22 |
+
return response_text
|
23 |
+
|
24 |
+
# 创建 Gradio 接口
|
25 |
+
iface = gr.Interface(
|
26 |
+
fn=chat,
|
27 |
+
inputs="text",
|
28 |
+
outputs="text",
|
29 |
+
title="Qwen Chatbot",
|
30 |
+
description="与 Qwen2.5-0.5B-Instruct-GGUF 模型对话"
|
31 |
+
)
|
32 |
+
|
33 |
+
iface.launch()
|