Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,31 @@
|
|
1 |
-
import
|
2 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
-
from peft import PeftModel
|
4 |
-
|
5 |
-
# 加载基础模型
|
6 |
-
base_model = AutoModelForCausalLM.from_pretrained("unsloth/Phi-4-unsloth-bnb-4bit")
|
7 |
-
tokenizer = AutoTokenizer.from_pretrained("unsloth/Phi-4-unsloth-bnb-4bit")
|
8 |
|
9 |
-
#
|
10 |
-
|
|
|
|
|
11 |
|
12 |
-
#
|
13 |
-
def
|
14 |
-
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
-
# Gradio 界面
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
-
|
22 |
-
|
|
|
1 |
+
import gradio as gr
|
2 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
+
# 加载模型和分词器
|
5 |
+
model_name = "muchuan-l/qwen2.5math1.5b-2v2-rev"
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
7 |
+
model = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto")
|
8 |
|
9 |
+
# 定义对话函数
|
10 |
+
def chat(input_text):
|
11 |
+
# 将输入文本转换为模型输入
|
12 |
+
inputs = tokenizer(input_text, return_tensors="pt").to("cuda")
|
13 |
+
|
14 |
+
# 生成回复
|
15 |
+
outputs = model.generate(**inputs, max_new_tokens=100)
|
16 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
17 |
+
|
18 |
+
return response
|
19 |
|
20 |
+
# 创建 Gradio 界面
|
21 |
+
interface = gr.Interface(
|
22 |
+
fn=chat, # 对话函数
|
23 |
+
inputs="text", # 输入类型
|
24 |
+
outputs="text", # 输出类型
|
25 |
+
title="Qwen2.5Math1.5B Chat", # 界面标题
|
26 |
+
description="A chatbot powered by Qwen2.5Math1.5B model.", # 界面描述
|
27 |
+
examples=["What is 2 + 2?", "Explain the Pythagorean theorem."] # 示例输入
|
28 |
+
)
|
29 |
|
30 |
+
# 启动界面
|
31 |
+
interface.launch()
|