Spaces:
Sleeping
Sleeping
Download api/main.py from chemenovausa/orbitchem-api: direct link, hf CLI and curl.
- Browser
- Download file 7.08 kB
-
https://huggingface.co/spaces/chemenovausa/orbitchem-api/resolve/main/api/main.py
- Command line
-
hf download hf://spaces/chemenovausa/orbitchem-api/api/main.py
-
curl -L -o main.py https://huggingface.co/spaces/chemenovausa/orbitchem-api/resolve/main/api/main.py
7.08 kB
| """ | |
| OrbitChem API v1.0 | |
| ChemeNova LLC — PROPRIETARY | |
| Aerospace and space materials chemistry intelligence built on IntelliForm Enterprise. | |
| Domain: LEO/GEO spacecraft materials, outgassing (NASA/ESA), radiation stability, | |
| thermal cycling fatigue, and pymatgen/matminer materials informatics. | |
| """ | |
| import sys, os | |
| sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | |
| from fastapi import FastAPI, HTTPException, Request | |
| from fastapi.middleware.cors import CORSMiddleware | |
| ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | |
| DB_PATH = os.path.join(ROOT, "data", "ingredients_db.csv") | |
| _EXTRA_ORIGINS = [o.strip() for o in os.getenv("ALLOWED_ORIGINS", "").split(",") if o.strip()] | |
| app = FastAPI( | |
| title="OrbitChem API", | |
| version="1.0.0", | |
| description="ChemeNova LLC — Aerospace & Space Materials Chemistry Intelligence", | |
| ) | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["http://localhost:5173", "https://chemenova.com", *_EXTRA_ORIGINS], | |
| allow_credentials=True, allow_methods=["*"], allow_headers=["*"], | |
| ) | |
| def _load_db(): | |
| import pandas as pd | |
| return pd.read_csv(DB_PATH) | |
| def _serialize(obj): | |
| if obj is None: return None | |
| if hasattr(obj, "__dict__"): | |
| return {k: _serialize(v) for k, v in obj.__dict__.items()} | |
| if isinstance(obj, dict): | |
| return {k: _serialize(v) for k, v in obj.items()} | |
| if isinstance(obj, list): | |
| return [_serialize(i) for i in obj] | |
| return obj | |
| def health(): | |
| return { | |
| "status": "ok", | |
| "service": "OrbitChem", | |
| "version": "1.0.0", | |
| "modules": [ | |
| "outgassing", "radiation_stability", "thermal_cycling", | |
| "circular_formulation_engine", "regulatory_guardian", | |
| "materials_adapter", "amdt", | |
| ], | |
| } | |
| async def outgassing(request: Request): | |
| """ | |
| NASA/ESA outgassing screening (ASTM E595). | |
| Body: { "blend": {"Material A": 60, ...} } | |
| Returns: TML, CVCM, VCM predictions, NASA/ESA pass/fail | |
| """ | |
| body = await request.json() | |
| blend = body.get("blend", {}) | |
| try: | |
| from modules.outgassing import run_outgassing_screen | |
| db = _load_db() | |
| result = run_outgassing_screen(blend, db) | |
| return _serialize(result) | |
| except Exception as e: | |
| raise HTTPException(status_code=500, detail=str(e)) | |
| async def radiation_stability(request: Request): | |
| """ | |
| Radiation stability prediction for spacecraft materials. | |
| Body: { | |
| "blend": {...}, | |
| "environment": "LEO", # LEO | GEO | deep_space | ISS | lunar | |
| "mission_years": 5.0 | |
| } | |
| """ | |
| body = await request.json() | |
| blend = body.get("blend", {}) | |
| environment = body.get("environment", "LEO") | |
| mission_yrs = float(body.get("mission_years", 5.0)) | |
| try: | |
| from modules.radiation_stability import run_radiation_stability | |
| db = _load_db() | |
| result = run_radiation_stability(blend, db, environment, mission_yrs) | |
| return _serialize(result) | |
| except Exception as e: | |
| raise HTTPException(status_code=500, detail=str(e)) | |
| async def thermal_cycling(request: Request): | |
| """ | |
| Thermal cycling fatigue prediction (Coffin-Manson + delamination G). | |
| Body: { | |
| "blend": {...}, | |
| "orbit": "LEO", # LEO | GEO | MEO | lunar | deep_space | |
| "mission_years": 5.0, | |
| "substrate": "aluminum" # aluminum | titanium | carbon_fiber | invar | silicon | steel | |
| } | |
| """ | |
| body = await request.json() | |
| blend = body.get("blend", {}) | |
| orbit = body.get("orbit", "LEO") | |
| mission_yrs = float(body.get("mission_years", 5.0)) | |
| substrate = body.get("substrate", "aluminum") | |
| try: | |
| from modules.thermal_cycling import run_thermal_cycling | |
| db = _load_db() | |
| result = run_thermal_cycling(blend, db, orbit, mission_yrs, substrate) | |
| return _serialize(result) | |
| except Exception as e: | |
| raise HTTPException(status_code=500, detail=str(e)) | |
| async def materials_profile(request: Request): | |
| """ | |
| Run pymatgen/matminer materials featurization on the blend. | |
| Body: { "blend": {...}, "vertical": "industrial" } | |
| """ | |
| body = await request.json() | |
| blend = body.get("blend", {}) | |
| vertical = body.get("vertical", "industrial") | |
| try: | |
| from modules.public_integrations import execute_public_integration_plan | |
| db = _load_db() | |
| result = execute_public_integration_plan( | |
| blend=blend, db=db, | |
| vertical=vertical, platform="orbitchem", | |
| ) | |
| return result.to_dict() | |
| except Exception as e: | |
| raise HTTPException(status_code=500, detail=str(e)) | |
| async def spacecraft_full(request: Request): | |
| """ | |
| Full OrbitChem qualification suite: outgassing + radiation + thermal cycling. | |
| Body: { | |
| "blend": {...}, | |
| "environment": "LEO", | |
| "orbit": "LEO", | |
| "mission_years": 5.0, | |
| "substrate": "aluminum" | |
| } | |
| """ | |
| body = await request.json() | |
| blend = body.get("blend", {}) | |
| environment = body.get("environment", "LEO") | |
| orbit = body.get("orbit", "LEO") | |
| mission_yrs = float(body.get("mission_years", 5.0)) | |
| substrate = body.get("substrate", "aluminum") | |
| try: | |
| from modules.outgassing import run_outgassing_screen | |
| from modules.radiation_stability import run_radiation_stability | |
| from modules.thermal_cycling import run_thermal_cycling | |
| from modules.circular_formulation_engine import run_circular_formulation_engine | |
| from modules.regulatory_guardian import run_regulatory_guardian | |
| db = _load_db() | |
| outgas = run_outgassing_screen(blend, db) | |
| rad = run_radiation_stability(blend, db, environment, mission_yrs) | |
| thermal = run_thermal_cycling(blend, db, orbit, mission_yrs, substrate) | |
| circular = run_circular_formulation_engine(blend, db) | |
| guardian = run_regulatory_guardian(blend, db, "industrial", circular) | |
| return { | |
| "outgassing": _serialize(outgas), | |
| "radiation": _serialize(rad), | |
| "thermal_cycling": _serialize(thermal), | |
| "circular": _serialize(circular), | |
| "guardian": _serialize(guardian), | |
| "qualification_summary": { | |
| "nasa_outgas_pass": outgas.nasa_pass, | |
| "esa_outgas_pass": outgas.esa_pass, | |
| "radiation_rating": rad.overall_rating, | |
| "thermal_pass": thermal.blend_passes, | |
| "guardian_status": guardian.status, | |
| }, | |
| } | |
| except Exception as e: | |
| raise HTTPException(status_code=500, detail=str(e)) | |
| if __name__ == "__main__": | |
| import uvicorn | |
| port = int(os.getenv("PORT", 8003)) | |
| uvicorn.run("api.main:app", host="0.0.0.0", port=port, reload=True) | |