Spaces:
Sleeping
Sleeping
Update app.py
Browse files4 unmodified lines56789103 unmodified lines141516171819204 unmodified lines2526272829303132333435363738394041424344454 unmodified linesapp = FastAPI()model_name = "google/flan-t5-base"tokenizer = AutoTokenizer.from_pretrained(model_name)3 unmodified lines@app.get("/")async def root():return PlainTextResponse("FLAN AI is running")@app.post("/")async def receive(request: Request):4 unmodified linesif not message:return PlainTextResponse("Пустое сообщение")prompt = f"Reply politely to this message: {message}"inputs = tokenizer(prompt, return_tensors="pt")with torch.no_grad():outputs = model.generate(**inputs,max_new_tokens=60,do_sample=False)reply = tokenizer.decode(outputs[0], skip_special_tokens=True).strip()if not reply:reply = "I am doing well! How can I help you?"return PlainTextResponse(reply)4 unmodified lines5678910113 unmodified lines151617181920214 unmodified lines2627282930313233343536373839404142434445464748495051525354554 unmodified linesapp = FastAPI()# Модель ~900MBmodel_name = "google/flan-t5-base"tokenizer = AutoTokenizer.from_pretrained(model_name)3 unmodified lines@app.get("/")async def root():return PlainTextResponse("FLAN BASE AI is running")@app.post("/")async def receive(request: Request):4 unmodified linesif not message:return PlainTextResponse("Пустое сообщение")# Улучшенный промптprompt = f"""You are a friendly and intelligent AI assistant.Give clear, slightly detailed and helpful answers.Avoid extremely short responses.User: {message}Answer:"""inputs = tokenizer(prompt, return_tensors="pt")with torch.no_grad():outputs = model.generate(**inputs,max_new_tokens=120,do_sample=True,temperature=0.7)reply = tokenizer.decode(outputs[0], skip_special_tokens=True).strip()if not reply:reply = "I'm here and ready to help!"return PlainTextResponse(reply)
app.py+15-5