Spaces:
Sleeping
Sleeping
Update app.py
Browse files4 unmodified lines5678910111213141516171819202122232425262728297 unmodified lines37383940414243444546474849505152535455565758591 unmodified line616263646566674 unmodified linesMODEL_NAME = "Qwen/Qwen2.5-1.5B-Instruct"tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)model = AutoModelForCausalLM.from_pretrained(MODEL_NAME,torch_dtype=torch.bfloat16,).to("cuda")@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."),},{"role": "user",7 unmodified linestokenize=True,return_dict=True,return_tensors="pt",).to("cuda")with torch.inference_mode():outputs = model.generate(**inputs,max_new_tokens=256,temperature=0.7,do_sample=True,)new_tokens = outputs[0][inputs["input_ids"].shape[-1]:]return tokenizer.decode(new_tokens,skip_special_tokens=True,)demo = gr.Interface(fn=fvb_ai,1 unmodified linelabel="Message",placeholder="Ask FVB AI anything..."),outputs=gr.Textbox(label="FVB AI"),title="FVB AI",description="FutureVidyabox AI",)4 unmodified lines5678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455567 unmodified lines6465666768697071727374757677787980818283848586878889901 unmodified line92939495969798991004 unmodified linesMODEL_NAME = "Qwen/Qwen2.5-1.5B-Instruct"# Load tokenizertokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)# Load modelmodel = AutoModelForCausalLM.from_pretrained(MODEL_NAME,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 usefulImportant 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": SYSTEM_PROMPT,},{"role": "user",7 unmodified linestokenize=True,return_dict=True,return_tensors="pt",).to(model.device)with torch.inference_mode():outputs = model.generate(**inputs,max_new_tokens=256,do_sample=True,temperature=0.7,top_p=0.8,repetition_penalty=1.1,)new_tokens = outputs[0][inputs["input_ids"].shape[-1]:]response = tokenizer.decode(new_tokens,skip_special_tokens=True,)return response.strip()demo = gr.Interface(fn=fvb_ai,1 unmodified linelabel="Message",placeholder="Ask FVB AI anything..."),outputs=gr.Textbox(label="FVB AI"),title="FVB AI",description="FutureVidyabox AI",)
app.py+45-12