requirements.txt
Browse filestorch
transformers
gradio
app.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
# 加载模型和Tokenizer
|
| 6 |
+
model_name = "TheBloke/MythoMax-L2-13B-GPTQ"
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 8 |
+
model = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto", torch_dtype=torch.float16)
|
| 9 |
+
|
| 10 |
+
def chat_with_xiaoying(user_input):
|
| 11 |
+
# Tokenize 用户输入
|
| 12 |
+
inputs = tokenizer(user_input, return_tensors="pt").to(model.device)
|
| 13 |
+
|
| 14 |
+
# 生成模型输出
|
| 15 |
+
outputs = model.generate(inputs["input_ids"], max_length=512, num_return_sequences=1)
|
| 16 |
+
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 17 |
+
|
| 18 |
+
return generated_text
|
| 19 |
+
|
| 20 |
+
# 设置Gradio界面
|
| 21 |
+
iface = gr.Interface(fn=chat_with_xiaoying, inputs="text", outputs="text")
|
| 22 |
+
iface.launch()
|