Spaces:
Paused
Paused
File size: 1,044 Bytes
81d8858 4e6b2ca 96d4b52 81d8858 c21f8a5 81d8858 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | 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()
@app.get("/scrape")
@app.get("/api/scrape")
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)
|