Spaces:
Runtime error
Runtime error
Update train.py
Browse files
train.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import os
|
| 2 |
import json
|
| 3 |
import torch
|
|
|
|
| 4 |
from transformers import AutoModelForCausalLM, AutoTokenizer, Trainer, TrainingArguments
|
| 5 |
from datasets import Dataset
|
| 6 |
|
|
@@ -156,3 +157,25 @@ trainer.train()
|
|
| 156 |
# **保存模型**
|
| 157 |
student.push_to_hub("Snow2222/fst-nnn", use_auth_token=hf_token)
|
| 158 |
tokenizer.push_to_hub("Snow2222/fst-nnn", use_auth_token=hf_token)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
import json
|
| 3 |
import torch
|
| 4 |
+
import gradio as gr
|
| 5 |
from transformers import AutoModelForCausalLM, AutoTokenizer, Trainer, TrainingArguments
|
| 6 |
from datasets import Dataset
|
| 7 |
|
|
|
|
| 157 |
# **保存模型**
|
| 158 |
student.push_to_hub("Snow2222/fst-nnn", use_auth_token=hf_token)
|
| 159 |
tokenizer.push_to_hub("Snow2222/fst-nnn", use_auth_token=hf_token)
|
| 160 |
+
|
| 161 |
+
# ✅ 部署 Gradio Web 界面
|
| 162 |
+
print("🎉 训练完成,启动 Gradio Web 界面...")
|
| 163 |
+
|
| 164 |
+
# 加载微调后的模型
|
| 165 |
+
pipe = pipeline("text-generation", model="Snow2222/fst-nnn", tokenizer="Snow2222/fst-nnn")
|
| 166 |
+
|
| 167 |
+
# 定义 Gradio 交互函数
|
| 168 |
+
def chat_response(prompt):
|
| 169 |
+
result = pipe(prompt, max_length=200)[0]["generated_text"]
|
| 170 |
+
return result
|
| 171 |
+
|
| 172 |
+
# 启动 Gradio Web 界面
|
| 173 |
+
iface = gr.Interface(
|
| 174 |
+
fn=chat_response,
|
| 175 |
+
inputs="text",
|
| 176 |
+
outputs="text",
|
| 177 |
+
title="AI 训练模型测试",
|
| 178 |
+
description="输入你的问题,模型将会自动回复!"
|
| 179 |
+
)
|
| 180 |
+
|
| 181 |
+
iface.launch(server_name="0.0.0.0", server_port=7860)
|