| from fastapi import FastAPI | |
| from transformers import pipeline | |
| ##create a new FASTAPI app | |
| app = FastAPI() | |
| ## Initialize the pipeline for text generation | |
| pipe = pipeline("text2text-generation", model="google/flan-t5-small") | |
| def home(): | |
| return {"message": "Welcome to the Text Generation API"} | |
| def generate_text(text: str): | |
| result = pipe(text) | |
| ##return the generated text in json format | |
| return {"generated_text": result[0]["generated_text"]} |