Spaces:
Sleeping
Sleeping
Sync server/app.py
Browse files116 unmodified lines117118119120121122116 unmodified linesreturn statedef main(host: str = "0.0.0.0", port: int = 8000) -> None:"""Entry point for ``uv run server`` or ``python -m methanol_apc_env.server.app``."""import uvicorn116 unmodified lines117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192116 unmodified linesreturn state# ── Gradio Web Interface with 3D Digital Twin ──if os.environ.get("ENABLE_WEB_INTERFACE", "").lower() in ("true", "1", "yes"):try:import gradio as gr_VIZ_URL = "/viz/3d-plant.html"_3D_IFRAME = f"""<iframe src="{_VIZ_URL}" width="100%" height="700"style="border: none; border-radius: 8px;"allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope"></iframe>"""def _get_env_info():return ("## Methanol APC Environment\n\n""| Property | Value |\n|---|---|\n""| **Actions** | 13 continuous variables |\n""| **Observations** | 30+ sensor readings |\n""| **Tasks** | 12 scenarios (easy to expert) |\n""| **Agents** | 4 (Reformer, Synthesis, Purification, Supervisory) |\n""| **Kinetic Models** | 5 (LHHW, Graaf, VBF, Seyfert, Nestler) |\n""| **Tests** | 86 passing, 92% coverage |\n""| **Integrations** | DWSIM, Cantera, ChemSep, Azure DT, OPC-UA |\n\n""### API Endpoints\n\n""| Endpoint | Method | Description |\n|---|---|---|\n""| `/health` | GET | Health check |\n""| `/reset` | POST | Reset environment |\n""| `/step` | POST | Take an action |\n""| `/viz/3d-plant.html` | GET | 3D Digital Twin |\n""| `/adt/state` | GET | Azure DT state |\n")with gr.Blocks(title="Methanol APC Environment",) as _gradio_app:gr.Markdown("# Methanol APC Environment\n*Multi-Agent RL for Autonomous Process Control of an Industrial Methanol Synthesis Plant*")with gr.Tabs():with gr.Tab("3D Digital Twin"):gr.HTML(_3D_IFRAME)with gr.Tab("Environment Info"):gr.Markdown(_get_env_info())with gr.Tab("API"):gr.Markdown("### Connect to this environment\n\n""```python\n""import requests\n\n""BASE = 'https://glitchfilter-methanol-apc-env.hf.space'\n\n""# Reset\n""r = requests.post(f'{BASE}/reset', json={'task_name': 'optimization'})\n""obs = r.json()['observation']\n""print(f'Temperature: {obs[\"temperature\"]:.1f} C')\n\n""# Step\n""action = {'action': {'feed_rate_h2': 5.0, 'feed_rate_co': 2.5,\n"" 'cooling_water_flow': 40.0, 'compressor_power': 65.0}}\n""r = requests.post(f'{BASE}/step', json=action)\n""print(r.json())\n""```")app = gr.mount_gradio_app(app, _gradio_app, path="/web")except ImportError:pass # Gradio not installed, skip web UIdef main(host: str = "0.0.0.0", port: int = 8000) -> None:"""Entry point for ``uv run server`` or ``python -m methanol_apc_env.server.app``."""import uvicorn
server/app.py+70