Spaces:
Sleeping
Sleeping
Download app.py from vishnu110/text2text-with-docorizing: direct link, hf CLI and curl.
- Browser
- Download file 798 Bytes
-
https://huggingface.co/spaces/vishnu110/text2text-with-docorizing/resolve/main/app.py
- Command line
-
hf download hf://spaces/vishnu110/text2text-with-docorizing/app.py
-
curl -L -o app.py https://huggingface.co/spaces/vishnu110/text2text-with-docorizing/resolve/main/app.py
798 Bytes
| from fastapi import FastAPI | |
| # Load model directly | |
| from transformers import AutoTokenizer, AutoModelForSeq2SeqLM | |
| ## create a new Fast App | |
| app = FastAPI() | |
| ## Initialize the text generation for python 10 not showing the pipeline | |
| tokenizer = AutoTokenizer.from_pretrained("google/flan-t5-small") | |
| model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-t5-small") | |
| def home(): | |
| return {"message": "Hello Wrold"} | |
| def generate(text:str): | |
| ## use the pipeline to generate text from given input text | |
| input_ids = tokenizer(text, return_tensors="pt").input_ids | |
| outputs = model.generate(input_ids) | |
| decoded_output = tokenizer.decode(outputs[0], skip_special_tokens=True) | |
| return {"output": decoded_output} |