Spaces:
Paused
Paused
Download app.py from ubuntu593/alt-scraper-api: direct link, hf CLI and curl.
- Browser
- Download file 1.04 kB
-
https://huggingface.co/spaces/ubuntu593/alt-scraper-api/resolve/main/app.py
- Command line
-
hf download hf://spaces/ubuntu593/alt-scraper-api/app.py
-
curl -L -o app.py https://huggingface.co/spaces/ubuntu593/alt-scraper-api/resolve/main/app.py
1.04 kB
| import os | |
| from fastapi import FastAPI, Header, HTTPException | |
| # Securely load the key from Hugging Face environment variables, with a default fallback key | |
| SECRET_KEY = os.getenv("AUTOALT_SECRET_KEY") | |
| try: | |
| from api import app, verify_key, run_scraper | |
| except ImportError: | |
| app = FastAPI() | |
| def run_scraper(x_autoalt_key: str = Header(None, alias="X-AutoAlt-Key")): | |
| # Block if the header is missing | |
| if not x_autoalt_key: | |
| raise HTTPException(status_code=401, detail="Unauthorized: X-AutoAlt-Key header is missing") | |
| # Block if the header value does not match your secret hash | |
| if x_autoalt_key != SECRET_KEY: | |
| raise HTTPException(status_code=403, detail="Forbidden: Invalid X-AutoAlt-Key") | |
| # If successful, return the scraped data | |
| return {"status": "success", "data": "Scraped data goes here"} | |
| if __name__ == "__main__": | |
| import uvicorn | |
| uvicorn.run(app, host="0.0.0.0", port=7860) | |