Spaces:
Running on Zero
Running on Zero
Download app.py from Kingadee505/Helo: direct link, hf CLI and curl.
- Browser
- Download file 1.39 kB
-
https://huggingface.co/spaces/Kingadee505/Helo/resolve/main/app.py
- Command line
-
hf download hf://spaces/Kingadee505/Helo/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Kingadee505/Helo/resolve/main/app.py
1.39 kB
| import gradio as gr | |
| import spaces | |
| import torch | |
| from transformers import AutoTokenizer, AutoModelForCausalLM | |
| MODEL_ID = "mradermacher/Huihui-Qwen3.5-27B-abliterated-GGUF" | |
| GGUF_FILE = "Huihui-Qwen3.5-27B-abliterated.Q4_K_M.gguf" | |
| tokenizer = AutoTokenizer.from_pretrained( | |
| MODEL_ID, | |
| gguf_file=GGUF_FILE | |
| ) | |
| model = AutoModelForCausalLM.from_pretrained( | |
| MODEL_ID, | |
| gguf_file=GGUF_FILE, | |
| torch_dtype=torch.bfloat16, | |
| device_map="auto" | |
| ) | |
| def chat(prompt): | |
| messages = [ | |
| { | |
| "role": "user", | |
| "content": prompt | |
| } | |
| ] | |
| text = tokenizer.apply_chat_template( | |
| messages, | |
| tokenize=False, | |
| add_generation_prompt=True | |
| ) | |
| inputs = tokenizer( | |
| text, | |
| return_tensors="pt" | |
| ).to("cuda") | |
| with torch.inference_mode(): | |
| output = model.generate( | |
| **inputs, | |
| max_new_tokens=256, | |
| temperature=0.7, | |
| do_sample=True, | |
| pad_token_id=tokenizer.eos_token_id | |
| ) | |
| answer = tokenizer.decode( | |
| output[0][inputs["input_ids"].shape[1]:], | |
| skip_special_tokens=True | |
| ) | |
| return answer | |
| demo = gr.Interface( | |
| fn=chat, | |
| inputs=gr.Textbox( | |
| label="Ask AI", | |
| lines=4 | |
| ), | |
| outputs=gr.Textbox( | |
| label="Answer", | |
| lines=14 | |
| ) | |
| ) | |
| demo.launch() |