Download app.py from Attacker3/xiaoying: direct link, hf CLI and curl.
- Browser
- Download file 801 Bytes
-
https://huggingface.co/spaces/Attacker3/xiaoying/resolve/main/app.py
- Command line
-
hf download hf://spaces/Attacker3/xiaoying/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Attacker3/xiaoying/resolve/main/app.py
801 Bytes
| import torch | |
| from transformers import AutoModelForCausalLM, AutoTokenizer | |
| import gradio as gr | |
| # 加载模型和Tokenizer | |
| model_name = "TheBloke/MythoMax-L2-13B-GPTQ" | |
| tokenizer = AutoTokenizer.from_pretrained(model_name) | |
| model = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto", torch_dtype=torch.float16) | |
| def chat_with_xiaoying(user_input): | |
| # Tokenize 用户输入 | |
| inputs = tokenizer(user_input, return_tensors="pt").to(model.device) | |
| # 生成模型输出 | |
| outputs = model.generate(inputs["input_ids"], max_length=512, num_return_sequences=1) | |
| generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True) | |
| return generated_text | |
| # 设置Gradio界面 | |
| iface = gr.Interface(fn=chat_with_xiaoying, inputs="text", outputs="text") | |
| iface.launch() | |