Spaces:
Sleeping
Sleeping
| 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] |