Spaces:
No application file
No application file
| from fastapi import FastAPI | |
| from transformers import pipeline | |
| ## create a new FastAPI App instance | |
| app = FastAPI() | |
| # Initialize the text generation pipeline | |
| pipe = pipeline('text2text-generation', model='google/fan-t5-small') | |
| def home(): | |
| return {"message": "Hello World"} | |
| # Define a function to hancle the GET request as '/generate' | |
| def generate_text(prompt: str): | |
| ## use the pipeline to generate text from given input prompt | |
| output = pipe(prompt, max_length=50, do_sample=True, temperature=0.6) | |
| ## return the generate text in JSON format | |
| return {"output": output[0]['generated_text']} | |