Spaces:
Runtime error
Runtime error
prashasti commited on
Commit ·
12bcdc7
1
Parent(s): 13558c9
UI changes
Browse files- Dockerfile +3 -6
- requirements.txt +6 -4
- server/app.py +7 -1
- ui.py +97 -0
Dockerfile
CHANGED
|
@@ -2,17 +2,14 @@ FROM python:3.12-slim
|
|
| 2 |
|
| 3 |
WORKDIR /app
|
| 4 |
|
| 5 |
-
|
|
|
|
| 6 |
RUN pip install --no-cache-dir uv
|
| 7 |
|
| 8 |
-
# copy everything
|
| 9 |
COPY . .
|
| 10 |
|
| 11 |
-
# install project from pyproject.toml
|
| 12 |
RUN uv pip install --system -e ".[dev]"
|
| 13 |
|
| 14 |
-
# expose API port (FastAPI default)
|
| 15 |
EXPOSE 8000
|
| 16 |
|
| 17 |
-
|
| 18 |
-
CMD ["server"]
|
|
|
|
| 2 |
|
| 3 |
WORKDIR /app
|
| 4 |
|
| 5 |
+
COPY requirements.txt .
|
| 6 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 7 |
RUN pip install --no-cache-dir uv
|
| 8 |
|
|
|
|
| 9 |
COPY . .
|
| 10 |
|
|
|
|
| 11 |
RUN uv pip install --system -e ".[dev]"
|
| 12 |
|
|
|
|
| 13 |
EXPOSE 8000
|
| 14 |
|
| 15 |
+
CMD ["python", "-m", "server.app"]
|
|
|
requirements.txt
CHANGED
|
@@ -1,6 +1,8 @@
|
|
| 1 |
-
fastapi=
|
| 2 |
-
uvicorn=
|
| 3 |
-
pydantic==2.6.4
|
| 4 |
openai>=1.0.0
|
|
|
|
| 5 |
openenv-core>=0.2.0
|
| 6 |
-
|
|
|
|
|
|
|
|
|
| 1 |
+
fastapi>=0.110.0
|
| 2 |
+
uvicorn>=0.29.0
|
|
|
|
| 3 |
openai>=1.0.0
|
| 4 |
+
python-dotenv>=1.0.0
|
| 5 |
openenv-core>=0.2.0
|
| 6 |
+
pydantic>=2.0.0
|
| 7 |
+
gradio>=4.0.0
|
| 8 |
+
requests>=2.31.0
|
server/app.py
CHANGED
|
@@ -14,6 +14,8 @@ import os
|
|
| 14 |
import uvicorn
|
| 15 |
from fastapi import FastAPI, HTTPException
|
| 16 |
from pydantic import BaseModel
|
|
|
|
|
|
|
| 17 |
|
| 18 |
# Import your environments
|
| 19 |
from tasks.task_simple import create_env as create_simple
|
|
@@ -108,8 +110,12 @@ def state():
|
|
| 108 |
except Exception as e:
|
| 109 |
raise HTTPException(status_code=400, detail=str(e))
|
| 110 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
def main():
|
| 112 |
-
port = int(os.getenv("PORT",
|
| 113 |
uvicorn.run(app, host="0.0.0.0", port=port)
|
| 114 |
|
| 115 |
|
|
|
|
| 14 |
import uvicorn
|
| 15 |
from fastapi import FastAPI, HTTPException
|
| 16 |
from pydantic import BaseModel
|
| 17 |
+
from ui import build_ui
|
| 18 |
+
import gradio as gr
|
| 19 |
|
| 20 |
# Import your environments
|
| 21 |
from tasks.task_simple import create_env as create_simple
|
|
|
|
| 110 |
except Exception as e:
|
| 111 |
raise HTTPException(status_code=400, detail=str(e))
|
| 112 |
|
| 113 |
+
# Mount Gradio UI inside FastAPI
|
| 114 |
+
ui = build_ui()
|
| 115 |
+
app = gr.mount_gradio_app(app, ui, path="/ui")
|
| 116 |
+
|
| 117 |
def main():
|
| 118 |
+
port = int(os.getenv("PORT", 8000))
|
| 119 |
uvicorn.run(app, host="0.0.0.0", port=port)
|
| 120 |
|
| 121 |
|
ui.py
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
|
| 4 |
+
BASE_URL = "http://localhost:8000"
|
| 5 |
+
|
| 6 |
+
current_logs = []
|
| 7 |
+
current_actions = []
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def reset_env(task):
|
| 11 |
+
global current_logs, current_actions
|
| 12 |
+
|
| 13 |
+
res = requests.post(f"{BASE_URL}/reset", json={"task": task})
|
| 14 |
+
data = res.json()
|
| 15 |
+
|
| 16 |
+
current_logs = data["observation"].get("logs", [])
|
| 17 |
+
current_actions = []
|
| 18 |
+
|
| 19 |
+
return (
|
| 20 |
+
format_logs(current_logs),
|
| 21 |
+
"Environment reset",
|
| 22 |
+
"Running..."
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def step_env(action):
|
| 27 |
+
global current_logs, current_actions
|
| 28 |
+
|
| 29 |
+
res = requests.post(f"{BASE_URL}/step", json={"action": action})
|
| 30 |
+
data = res.json()
|
| 31 |
+
|
| 32 |
+
obs = data["observation"]
|
| 33 |
+
reward = data["reward"]
|
| 34 |
+
done = data["done"]
|
| 35 |
+
|
| 36 |
+
current_logs = obs.get("logs", [])
|
| 37 |
+
current_actions.append(f"{action} → reward={reward}")
|
| 38 |
+
|
| 39 |
+
status = f"{'✅ Resolved' if done else 'Running'} | Reward: {reward}"
|
| 40 |
+
|
| 41 |
+
return (
|
| 42 |
+
format_logs(current_logs),
|
| 43 |
+
"\n".join(current_actions),
|
| 44 |
+
status
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def format_logs(logs):
|
| 49 |
+
return "\n".join([f"• {log}" for log in logs])
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
def build_ui():
|
| 53 |
+
with gr.Blocks() as demo:
|
| 54 |
+
gr.Markdown("#DebugOps AI Environment")
|
| 55 |
+
gr.Markdown("Interactive incident response simulator")
|
| 56 |
+
|
| 57 |
+
task_dropdown = gr.Dropdown(
|
| 58 |
+
["simple", "multi_service", "critical"],
|
| 59 |
+
label="Select Task",
|
| 60 |
+
value="simple"
|
| 61 |
+
)
|
| 62 |
+
|
| 63 |
+
reset_btn = gr.Button("Reset Environment")
|
| 64 |
+
|
| 65 |
+
logs_box = gr.Textbox(label="Logs", lines=10)
|
| 66 |
+
actions_box = gr.Textbox(label="Actions Taken", lines=10)
|
| 67 |
+
status_box = gr.Textbox(label="Status")
|
| 68 |
+
|
| 69 |
+
with gr.Row():
|
| 70 |
+
gr.Button("Restart API").click(
|
| 71 |
+
lambda: step_env("restart_api"),
|
| 72 |
+
outputs=[logs_box, actions_box, status_box]
|
| 73 |
+
)
|
| 74 |
+
gr.Button("Restart DB").click(
|
| 75 |
+
lambda: step_env("restart_db"),
|
| 76 |
+
outputs=[logs_box, actions_box, status_box]
|
| 77 |
+
)
|
| 78 |
+
gr.Button("Restart Cache").click(
|
| 79 |
+
lambda: step_env("restart_cache"),
|
| 80 |
+
outputs=[logs_box, actions_box, status_box]
|
| 81 |
+
)
|
| 82 |
+
gr.Button("Scale Up").click(
|
| 83 |
+
lambda: step_env("scale_up"),
|
| 84 |
+
outputs=[logs_box, actions_box, status_box]
|
| 85 |
+
)
|
| 86 |
+
gr.Button("No-op").click(
|
| 87 |
+
lambda: step_env("noop"),
|
| 88 |
+
outputs=[logs_box, actions_box, status_box]
|
| 89 |
+
)
|
| 90 |
+
|
| 91 |
+
reset_btn.click(
|
| 92 |
+
reset_env,
|
| 93 |
+
inputs=task_dropdown,
|
| 94 |
+
outputs=[logs_box, actions_box, status_box]
|
| 95 |
+
)
|
| 96 |
+
|
| 97 |
+
return demo
|