Spaces:
Sleeping
Sleeping
Update app.py
Browse files2 unmodified lines34567898 unmodified lines1819202122232425262728293031323334353637383940414243444546474849505152532 unmodified linesfrom transformers import AutoModelForCausalLM, AutoTokenizerimport spaces# Your exact repository and GGUF pathREPO_ID = "NiftyOracleAI/NiftyOracle-Coder-30B"GGUF_FILE = "gguf/codesymb_1b_chat_FP16.gguf"8 unmodified lines)print("β Model loaded into memory!")# ZeroGPU decorator: dynamically attaches the GPU when a prompt is sent@spaces.GPUdef chat_with_codesymb(message, history):# ChatML prompt formattingprompt = (f"<|system|>\nYou are CodeSymb, a world-class coding assistant by NiftyOracleAI.\n"f"<|user|>\n{message}\n"f"<|assistant|>\n")inputs = tokenizer(prompt, return_tensors="pt").to(model.device)with torch.no_grad():outputs = model.generate(**inputs,max_new_tokens=512,temperature=0.3,do_sample=True,pad_token_id=tokenizer.eos_token_id)# Extract only the generated replyresponse = tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True)return response# Clean Gradio chat interfacedemo = gr.ChatInterface(fn=chat_with_codesymb,title="CodeSymb-1B Chat (ZeroGPU)",description="Live inference for CodeSymb-1B FP16 GGUF running on Hugging Face ZeroGPU.")if __name__ == "__main__":2 unmodified lines3456788 unmodified lines171819202122232425262728293031323334353637383940414243444546474849505152532 unmodified linesfrom transformers import AutoModelForCausalLM, AutoTokenizerimport spacesREPO_ID = "NiftyOracleAI/NiftyOracle-Coder-30B"GGUF_FILE = "gguf/codesymb_1b_chat_FP16.gguf"8 unmodified lines)print("β Model loaded into memory!")@spaces.GPUdef chat_with_codesymb(message, history):# Standard format without unmapped special tag conflictsprompt = f"User: {message}\nAssistant:"inputs = tokenizer(prompt, return_tensors="pt").to(model.device)with torch.no_grad():outputs = model.generate(**inputs,max_new_tokens=256,temperature=0.6,top_p=0.9,repetition_penalty=1.25, # π Breaks the infinite repetition loop!no_repeat_ngram_size=3, # π Prevents repeating 3-word loopsdo_sample=True,pad_token_id=tokenizer.eos_token_id if tokenizer.eos_token_id is not None else 2)response = tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True)# Strip any stray prompt echoesif "User:" in response:response = response.split("User:")[0]return response.strip()demo = gr.ChatInterface(fn=chat_with_codesymb,title="CodeSymb-1B Chat (ZeroGPU)",description="Live inference for CodeSymb-1B FP16 GGUF.")if __name__ == "__main__":
app.py+15-15