Spaces:
Sleeping
Sleeping
Update app.py
Browse files2 unmodified lines34566788 unmodified lines1718192120212425262728292223242526272829363730313233343539363738423940414243444445464647484950505152532 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 formatting prompt = ( f"<|system|>\nYou are CodeSymb, a world-class coding assistant by NiftyOracleAI.\n" f"<|user|>\n{message}\n" f"<|assistant|>\n" ) # Standard format without unmapped special tag conflicts prompt = f"User: {message}\nAssistant:" inputs = tokenizer(prompt, return_tensors="pt").to(model.device) with torch.no_grad(): outputs = model.generate( **inputs, max_new_tokens=512, temperature=0.3, 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 loops do_sample=True, pad_token_id=tokenizer.eos_token_id pad_token_id=tokenizer.eos_token_id if tokenizer.eos_token_id is not None else 2 ) # Extract only the generated reply response = tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True) # Strip any stray prompt echoes if "User:" in response: response = response.split("User:")[0] return response return response.strip()
# 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." description="Live inference for CodeSymb-1B FP16 GGUF.")
if __name__ == "__main__":app.py+15-15