Spaces:
Runtime error
Runtime error
Download app.py from Sanket17/google-flan-api: direct link, hf CLI and curl.
- Browser
- Download file 571 Bytes
-
https://huggingface.co/spaces/Sanket17/google-flan-api/resolve/main/app.py
- Command line
-
hf download hf://spaces/Sanket17/google-flan-api/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Sanket17/google-flan-api/resolve/main/app.py
571 Bytes
| from fastapi import FastAPI | |
| # Use a pipeline as a high-level helper | |
| from transformers import pipeline | |
| pipe = pipeline("translation", model="google-t5/t5-base") | |
| import os | |
| # Set cache directory to a local writable directory | |
| os.environ['HF_HOME'] = './cache' | |
| os.environ['TRANSFORMERS_CACHE'] = './cache' | |
| os.environ['TORCH_HOME'] = './cache' | |
| # Ensure the directory exists | |
| os.makedirs('./cache', exist_ok=True) | |
| app = FastAPI() | |
| def home(): | |
| return {"Hello": "World"} | |
| def ask(prompt: str): | |
| result = pipe(prompt) | |
| return result[0] |