Spaces:
Sleeping
Sleeping
Update app.py
Browse files4 unmodified lines56789101112131213141516171819202122232425262728293031323334353637383940414243444546474849505152212223242526535455567 unmodified lines6465664067686970717246737475767778798052818283848586878889901 unmodified line9293946495969798991004 unmodified lines
MODEL_NAME = "Qwen/Qwen2.5-1.5B-Instruct"
# Load tokenizertokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
# Load modelmodel = AutoModelForCausalLM.from_pretrained( MODEL_NAME, torch_dtype=torch.bfloat16,).to("cuda") torch_dtype="auto", device_map="auto",)
SYSTEM_PROMPT = """You are FVB AI, the official AI assistant of FutureVidyabox.
Your role:- Help FutureVidyabox students, staff, and customers.- Explain educational topics clearly.- Help with mathematics, science, computers, programming, and general education.- Help with programming and code generation.- Help debug code and explain programming concepts.- Help answer FutureVidyabox customer-support questions when the required information is provided.
Personality:- Friendly- Helpful- Clear- Patient- Professional- Concise when a short answer is enough- Give step-by-step explanations when useful
Important rules:- Do not pretend to know private FutureVidyabox information that has not been provided.- Do not invent company policies, prices, contact information, or services.- If you do not know something, clearly say that you do not know.- For programming questions, provide useful and properly formatted code when appropriate.- For educational questions, explain concepts rather than only giving an answer.
You are FVB AI, not ChatGPT."""
@spaces.GPU(duration=45)def fvb_ai(message): messages = [ { "role": "system", "content": ( "You are FVB AI, the helpful AI assistant of FutureVidyabox. " "Be friendly, accurate, concise, and helpful. " "You can help with education, customer support, programming, " "and general questions." ), "content": SYSTEM_PROMPT, }, { "role": "user",7 unmodified lines tokenize=True, return_dict=True, return_tensors="pt", ).to("cuda") ).to(model.device)
with torch.inference_mode(): outputs = model.generate( **inputs, max_new_tokens=256, temperature=0.7, do_sample=True, temperature=0.7, top_p=0.8, repetition_penalty=1.1, )
new_tokens = outputs[0][inputs["input_ids"].shape[-1]:]
return tokenizer.decode( response = tokenizer.decode( new_tokens, skip_special_tokens=True, )
return response.strip()
demo = gr.Interface( fn=fvb_ai,1 unmodified line label="Message", placeholder="Ask FVB AI anything..." ), outputs=gr.Textbox(label="FVB AI"), outputs=gr.Textbox( label="FVB AI" ), title="FVB AI", description="FutureVidyabox AI",)app.py+45-12