Spaces:
Sleeping
Sleeping
Update app.py
Browse files4 unmodified lines5678910113 unmodified lines15161717181920214 unmodified lines262728282930313233343536373839404142433536444546474849505142525354554 unmodified lines
app = FastAPI()
# Модель ~900MBmodel_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") return PlainTextResponse("FLAN BASE AI is running")
@app.post("/")async def receive(request: Request):4 unmodified lines if not message: return PlainTextResponse("Пустое сообщение")
prompt = f"Reply politely to this message: {message}" # Улучшенный промпт 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=60, do_sample=False 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 am doing well! How can I help you?" reply = "I'm here and ready to help!"
return PlainTextResponse(reply)
app.py+15-5