Spaces:
Sleeping
Sleeping
Update app.py
Browse files22 unmodified lines232425262627281 unmodified line30313234353334353736373938394243444546404142434445464753484950515215 unmodified lines6869707571727322 unmodified lines "Use lowercase, slang, and act like a real person chatting.")
def respond(message, history): messages = [{"role": "system", "content": SYSTEM_PROMPT}] for h in history:1 unmodified line messages.append({"role": "user", "content": message})
try: # Force tokenize=True and return tensors properly input_ids = tokenizer.apply_chat_template( # Get the formatted prompt as a string first prompt = tokenizer.apply_chat_template( messages, return_tensors="pt", tokenize=False, add_generation_prompt=True, tokenize=True, ) # Make sure it's a tensor, not a dict if isinstance(input_ids, dict): input_ids = input_ids["input_ids"] input_ids = input_ids.to(model.device) # Then tokenize separately to get a clean tensor inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
streamer = TextIteratorStreamer( tokenizer, skip_prompt=True, skip_special_tokens=True )
gen_kwargs = dict( input_ids=input_ids, input_ids=inputs.input_ids, attention_mask=inputs.attention_mask, max_new_tokens=120, do_sample=True, temperature=0.85,15 unmodified lines traceback.print_exc() yield f"[error] {str(e)}"
custom_css = """@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');
app.py+7-12