Spaces:
Sleeping
Sleeping
Update app.py
Browse files12344 unmodified lines91011121314153 unmodified lines192021222324import osfrom threading import Threadimport gradio as gr4 unmodified linesMODEL_ID = os.environ.get("MODEL_ID", "lukey03/Qwen3.5-9B-abliterated")tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)model = AutoModelForCausalLM.from_pretrained(MODEL_ID, torch_dtype=torch.bfloat16)model.to("cuda")3 unmodified linesreturn c or ""@spaces.GPU(duration=120)def generate(messages_json: str, max_tokens: int = 1024, temperature: float = 0.7) -> str:msgs = json.loads(messages_json)12344 unmodified lines91011121314153 unmodified lines19202122232425262728293031323334353637383940414243444546import os, jsonfrom threading import Threadimport gradio as gr4 unmodified linesMODEL_ID = os.environ.get("MODEL_ID", "lukey03/Qwen3.5-9B-abliterated")tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)model = AutoModelForCausalLM.from_pretrained(MODEL_ID, dtype=torch.bfloat16)model.to("cuda")3 unmodified linesreturn c or ""@spaces.GPU(duration=120)def chat(message, history):msgs = [{"role": h["role"], "content": to_text(h["content"])} for h in history]msgs.append({"role": "user", "content": to_text(message)})ids = tokenizer.apply_chat_template(msgs, add_generation_prompt=True, return_tensors="pt",return_dict=True, enable_thinking=False,).to("cuda")streamer = TextIteratorStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)Thread(target=model.generate, kwargs=dict(**ids, streamer=streamer, max_new_tokens=1024,do_sample=True, temperature=0.7, top_p=0.95,)).start()text = ""for tok in streamer:text += tokyield text@spaces.GPU(duration=120)def generate(messages_json: str, max_tokens: int = 1024, temperature: float = 0.7) -> str:msgs = json.loads(messages_json)
app.py+24-2