from transformers import pipeline from fastapi import FastAPI import os os.environ['TRANSFORMERS_CACHE'] = '/.cache/huggingface/hub' app = FastAPI() pipe = pipeline("text2text-generation", model="google/flan-t5-small") @app.get("/") async def home(): return "hello world" @app.get("/generate") async def generate(text:str): res = pipe(text) return {"output":res[0]['generated_text']}