Download app.py from M-Rizwan0099/Text-2-text-with-dockers: direct link, hf CLI and curl.
- Browser
- Download file 506 Bytes
-
https://huggingface.co/spaces/M-Rizwan0099/Text-2-text-with-dockers/resolve/main/app.py
- Command line
-
hf download hf://spaces/M-Rizwan0099/Text-2-text-with-dockers/app.py
-
curl -L -o app.py https://huggingface.co/spaces/M-Rizwan0099/Text-2-text-with-dockers/resolve/main/app.py
506 Bytes
| 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"]} |