poseidon666 commited on
Commit
28f016b
·
verified ·
1 Parent(s): fcc79cd

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. Dockerfile +3 -3
  2. server/app.py +30 -7
Dockerfile CHANGED
@@ -76,8 +76,8 @@ EXPOSE 7860
76
 
77
  # Health check
78
  HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
79
- CMD python -c "import requests; requests.get('http://localhost:7860/')" || exit 1
80
 
81
- # Run the app with python
82
  ENV ENABLE_WEB_INTERFACE=true
83
- CMD ["sh", "-c", "cd /app/env && python -m server.app"]
 
76
 
77
  # Health check
78
  HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
79
+ CMD curl -f http://localhost:7860/health || exit 1
80
 
81
+ # Run the app with uvicorn
82
  ENV ENABLE_WEB_INTERFACE=true
83
+ CMD ["sh", "-c", "cd /app/env && uvicorn server.app:app --host 0.0.0.0 --port 7860"]
server/app.py CHANGED
@@ -1,10 +1,11 @@
1
  # -*- coding: utf-8 -*-
2
  """
3
- Minimal Gradio server for the Quantum Circuit Optimization Environment.
4
 
5
  Deployment spec:
6
- - Gradio UI at root
7
- - Port: 7860 (managed externally by HF Spaces)
 
8
  """
9
 
10
  import json
@@ -19,6 +20,7 @@ for _p in (_ROOT, _HERE):
19
  if _p not in sys.path:
20
  sys.path.insert(0, _p)
21
 
 
22
  import gradio as gr
23
 
24
  from models import ActionType, GateType, QuantumAction, QuantumObservation
@@ -27,6 +29,23 @@ from server.my_env_environment import QuantumCircuitEnvironment
27
  logging.basicConfig(level=logging.INFO)
28
  logger = logging.getLogger(__name__)
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  # ---------------------------------------------------------------------------
31
  # Global environment instance (for Gradio UI)
32
  # ---------------------------------------------------------------------------
@@ -186,7 +205,7 @@ def do_step(action_type, gate_type, qubit_0, qubit_1, parameter):
186
 
187
 
188
  # ---------------------------------------------------------------------------
189
- # Minimal Gradio UI
190
  # ---------------------------------------------------------------------------
191
 
192
  def create_gradio_app() -> gr.Blocks:
@@ -226,12 +245,16 @@ def create_gradio_app() -> gr.Blocks:
226
 
227
 
228
  # ---------------------------------------------------------------------------
229
- # Create Gradio app
230
  # ---------------------------------------------------------------------------
231
- app = create_gradio_app()
 
 
 
232
 
233
  # ---------------------------------------------------------------------------
234
  # Entry Point (for local testing only)
235
  # ---------------------------------------------------------------------------
236
  if __name__ == "__main__":
237
- app.launch(server_name="0.0.0.0", server_port=7860)
 
 
1
  # -*- coding: utf-8 -*-
2
  """
3
+ FastAPI server with Gradio UI for the Quantum Circuit Optimization Environment.
4
 
5
  Deployment spec:
6
+ - Root endpoint: GET / → health check JSON
7
+ - Gradio UI: mounted at /
8
+ - Port: 7860 (managed externally by HF Spaces)
9
  """
10
 
11
  import json
 
20
  if _p not in sys.path:
21
  sys.path.insert(0, _p)
22
 
23
+ from fastapi import FastAPI
24
  import gradio as gr
25
 
26
  from models import ActionType, GateType, QuantumAction, QuantumObservation
 
29
  logging.basicConfig(level=logging.INFO)
30
  logger = logging.getLogger(__name__)
31
 
32
+ # ---------------------------------------------------------------------------
33
+ # FastAPI base app
34
+ # ---------------------------------------------------------------------------
35
+ fastapi_app = FastAPI(title="Quantum Circuit Optimizer")
36
+
37
+ @fastapi_app.get("/health")
38
+ def health():
39
+ return {"status": "ok", "message": "Quantum Circuit Optimizer is running"}
40
+
41
+ @fastapi_app.get("/api/info")
42
+ def info():
43
+ return {
44
+ "name": "Quantum Circuit Optimization Environment",
45
+ "version": "1.0.0",
46
+ "gradio_ui": "Available at root path /"
47
+ }
48
+
49
  # ---------------------------------------------------------------------------
50
  # Global environment instance (for Gradio UI)
51
  # ---------------------------------------------------------------------------
 
205
 
206
 
207
  # ---------------------------------------------------------------------------
208
+ # Gradio UI
209
  # ---------------------------------------------------------------------------
210
 
211
  def create_gradio_app() -> gr.Blocks:
 
245
 
246
 
247
  # ---------------------------------------------------------------------------
248
+ # Create Gradio app and mount to FastAPI
249
  # ---------------------------------------------------------------------------
250
+ demo = create_gradio_app()
251
+
252
+ # Mount Gradio to FastAPI at root path
253
+ app = gr.mount_gradio_app(fastapi_app, demo, path="/")
254
 
255
  # ---------------------------------------------------------------------------
256
  # Entry Point (for local testing only)
257
  # ---------------------------------------------------------------------------
258
  if __name__ == "__main__":
259
+ import uvicorn
260
+ uvicorn.run(app, host="0.0.0.0", port=7860)