Spaces:
Runtime error
Runtime error
Download app.py from ntrinh/text2textdocker: direct link, hf CLI and curl.
- Browser
- Download file 613 Bytes
-
https://huggingface.co/spaces/ntrinh/text2textdocker/resolve/main/app.py
- Command line
-
hf download hf://spaces/ntrinh/text2textdocker/app.py
-
curl -L -o app.py https://huggingface.co/spaces/ntrinh/text2textdocker/resolve/main/app.py
613 Bytes
| from fastapi import FastAPI | |
| from transformers import pipeline | |
| # create a new Fastapi instance | |
| app = FastAPI() | |
| # initialize the text generation pipeline | |
| pipe = pipeline("text2text-generation", model="google/flan-t5-small") | |
| # define the endpoint for this application | |
| def home(): | |
| return ({"message":"hello world!"}) | |
| # define a function to handle the GET request at '/generate' | |
| def generate(text:str): | |
| # use the pipeline to generate text from given input text | |
| result = pipe(text) | |
| # return the generated text | |
| return {"output": result[0]['generated_text']} | |