Spaces:
Sleeping
Sleeping
File size: 1,949 Bytes
d2226ad 5b85009 d2226ad | 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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | import os
import requests
from tqdm import tqdm
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from fastapi.middleware.cors import CORSMiddleware
from config import settings
from api_endpoints import router
app = FastAPI(
title = "Project Orb API",
description = "Astronomical calculation engine for rendering the night sky.",
version = "1.0.0"
)
origins = [
"http://localhost:5173", # Vite default
"http://localhost:3000", # React default
"https://SubhojitGhimire.hf.space", # REMOVE THIS LINE FOR YOUR PERSONAL DEPLOYMENT
"https://SubhojitGhimire.github.io", # REMOVE THIS LINE FOR YOUR PERSONAL DEPLOYMENT
]
app.add_middleware(
CORSMiddleware,
allow_origins = origins,
allow_credentials = True,
allow_methods = ["*"],
allow_headers = ["*"],
)
app.include_router(router, prefix = "/api")
# @app.get("/")
# def root():
# return {"message": "Welcome to Project Orb. Visit /docs for API documentation."}
@app.on_event("startup")
async def startup_event():
settings.DATA_DIR.mkdir(parents = True, exist_ok = True)
if not settings.EPHEMERIS_FILE.exists():
print(f"Ephemeris file missing. Downloading...")
from skyfield.api import Loader
load = Loader(settings.DATA_DIR)
load('de421.bsp')
if not settings.HIPPARCOS_RAW.exists():
from skyfield.api import Loader
from skyfield.data import hipparcos
print(f"Star catalog missing. Downloading...")
load = Loader(settings.DATA_DIR)
load.open(hipparcos.URL)
if os.path.exists('hip_main.dat'):
os.rename('hip_main.dat', settings.HIPPARCOS_RAW)
app.mount(
"/",
StaticFiles(directory="frontend/dist", html=True),
name="frontend"
)
if __name__ == "__main__":
import uvicorn
port = int(os.environ.get("PORT", 8000))
uvicorn.run("app.main:app", host = "0.0.0.0", port = port, reload = True)
|