Spaces:
Sleeping
Sleeping
Update app.py
Browse files7 unmodified lines8910111213141516171819202122232425267 unmodified linestokenizer = AutoTokenizer.from_pretrained(model_name)model = AutoModelForSeq2SeqLM.from_pretrained(model_name)def respond(message, history):# STEP 1: Tokenizationinputs = tokenizer(message, return_tensors="pt")# STEP 2: Inferencewith torch.no_grad():outputs = model.generate(**inputs, max_new_tokens=128)# STEP 3: Decodingreturn tokenizer.decode(outputs[0], skip_special_tokens=True)# 2. Setup the UIdemo = gr.ChatInterface(fn=respond, title="Basic Transformer Bot")if __name__ == "__main__":demo.launch()7 unmodified lines8910111213141516171819202122232425262728293031323334357 unmodified linestokenizer = AutoTokenizer.from_pretrained(model_name)model = AutoModelForSeq2SeqLM.from_pretrained(model_name)def respond(message, history, system_message):# Update: Prepend persona instructions to the user promptprompt = f"Instruction: {system_message}\nUser: {message}"inputs = tokenizer(prompt, return_tensors="pt")with torch.no_grad():outputs = model.generate(**inputs, max_new_tokens=128)return tokenizer.decode(outputs[0], skip_special_tokens=True)# UI Update: Adding 'additional_inputs' for the Personademo = gr.ChatInterface(fn=respond,title="NSCC IT Support Specialist",additional_inputs=[gr.Textbox(value="You are a professional IT support technician at NSCC. Be technical and polite.",label="System Persona")])if __name__ == "__main__":demo.launch()
app.py+16-7