Spaces:
Sleeping
Sleeping
deploy via scripts/deploy_to_space.py
Browse files- scripts/hello_space.py +68 -0
scripts/hello_space.py
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""scripts/hello_space.py - Day-0 deployment-substrate placeholder app.
|
| 2 |
+
|
| 3 |
+
This is the *minimal* FastAPI app you push to your Hugging Face Space the
|
| 4 |
+
night before the hackathon to prove the deployment substrate works:
|
| 5 |
+
|
| 6 |
+
Step 1: Create a public HF Space called e.g. ``qubit-medic-hello``
|
| 7 |
+
Step 2: Push our slim Dockerfile + this file (rename to ``app.py``)
|
| 8 |
+
Step 3: Hit ``/healthz`` from your browser -> proves networking works
|
| 9 |
+
Step 4: Hit ``/healthz`` from a Colab cell -> proves Colab can reach it
|
| 10 |
+
|
| 11 |
+
Once all four pass, replace this file with the real env (the real
|
| 12 |
+
:mod:`qubit_medic.server.app` already implements the same ``/healthz``
|
| 13 |
+
endpoint, so the Day-0 contract carries forward).
|
| 14 |
+
|
| 15 |
+
Run locally::
|
| 16 |
+
|
| 17 |
+
python -m scripts.hello_space # listens on :7860
|
| 18 |
+
"""
|
| 19 |
+
from __future__ import annotations
|
| 20 |
+
|
| 21 |
+
import os
|
| 22 |
+
import sys
|
| 23 |
+
|
| 24 |
+
import stim
|
| 25 |
+
from fastapi import FastAPI
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
app = FastAPI(
|
| 29 |
+
title="Qubit-Medic - Hello Space",
|
| 30 |
+
description="Day-0 deployment-substrate placeholder. Proves Stim imports "
|
| 31 |
+
"and the HTTP server is reachable. Replace with the real env "
|
| 32 |
+
"once Section 2 of the plan passes local validation.",
|
| 33 |
+
version="0.0.1-placeholder",
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
@app.get("/")
|
| 38 |
+
def root() -> dict:
|
| 39 |
+
return {
|
| 40 |
+
"service": "qubit-medic-hello",
|
| 41 |
+
"status": "placeholder live",
|
| 42 |
+
"next": "POST /reset and /step will become available once the real "
|
| 43 |
+
"DecoderEnvironment is pushed.",
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
@app.get("/healthz")
|
| 48 |
+
def healthz() -> dict:
|
| 49 |
+
return {
|
| 50 |
+
"ok": True,
|
| 51 |
+
"stim_version": stim.__version__,
|
| 52 |
+
"python_version": sys.version.split()[0],
|
| 53 |
+
"service": "qubit-medic-hello",
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def _main() -> None:
|
| 58 |
+
import uvicorn
|
| 59 |
+
uvicorn.run(
|
| 60 |
+
"scripts.hello_space:app",
|
| 61 |
+
host=os.getenv("HOST", "0.0.0.0"),
|
| 62 |
+
port=int(os.getenv("PORT", "7860")),
|
| 63 |
+
log_level="info",
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
if __name__ == "__main__":
|
| 68 |
+
_main()
|