Spaces:
Sleeping
Sleeping
Add HTML UI
Browse files
main.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import uvicorn
|
| 2 |
from fastapi import FastAPI, HTTPException
|
|
|
|
| 3 |
from pydantic import BaseModel
|
| 4 |
from env.core import CloudOpsEnvironment
|
| 5 |
from models import Action as ActionModel
|
|
@@ -7,9 +8,79 @@ from models import Action as ActionModel
|
|
| 7 |
app = FastAPI(title="CloudOps Optimizer")
|
| 8 |
env = CloudOpsEnvironment()
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
async def root():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
return {
|
| 14 |
"name": "CloudOps Optimizer",
|
| 15 |
"version": "1.0.0",
|
|
|
|
| 1 |
import uvicorn
|
| 2 |
from fastapi import FastAPI, HTTPException
|
| 3 |
+
from fastapi.responses import HTMLResponse
|
| 4 |
from pydantic import BaseModel
|
| 5 |
from env.core import CloudOpsEnvironment
|
| 6 |
from models import Action as ActionModel
|
|
|
|
| 8 |
app = FastAPI(title="CloudOps Optimizer")
|
| 9 |
env = CloudOpsEnvironment()
|
| 10 |
|
| 11 |
+
HTML_CONTENT = """
|
| 12 |
+
<!DOCTYPE html>
|
| 13 |
+
<html>
|
| 14 |
+
<head>
|
| 15 |
+
<title>CloudOps Optimizer</title>
|
| 16 |
+
<style>
|
| 17 |
+
body { font-family: Arial, sans-serif; max-width: 800px; margin: 0 auto; padding: 20px; }
|
| 18 |
+
h1 { color: #2c5aa0; }
|
| 19 |
+
.card { background: #f5f5f5; padding: 15px; margin: 10px 0; border-radius: 8px; }
|
| 20 |
+
.btn { background: #2c5aa0; color: white; padding: 10px 20px; border: none; border-radius: 5px; cursor: pointer; }
|
| 21 |
+
.btn:hover { background: #1a3d6e; }
|
| 22 |
+
#output { background: #1e1e1e; color: #00ff00; padding: 15px; border-radius: 5px; white-space: pre-wrap; font-family: monospace; }
|
| 23 |
+
input, select { padding: 10px; margin: 5px; border-radius: 5px; border: 1px solid #ccc; }
|
| 24 |
+
</style>
|
| 25 |
+
</head>
|
| 26 |
+
<body>
|
| 27 |
+
<h1>☁️ CloudOps Optimizer</h1>
|
| 28 |
+
<p>Simulate cloud infrastructure cost and performance optimization</p>
|
| 29 |
+
|
| 30 |
+
<div class="card">
|
| 31 |
+
<h3>Reset Environment</h3>
|
| 32 |
+
<select id="task">
|
| 33 |
+
<option value="easy">Easy - Right-Sizing</option>
|
| 34 |
+
<option value="medium">Medium - Latency Fix</option>
|
| 35 |
+
<option value="hard">Hard - Balance Optimization</option>
|
| 36 |
+
</select>
|
| 37 |
+
<button class="btn" onclick="resetEnv()">Reset</button>
|
| 38 |
+
</div>
|
| 39 |
+
|
| 40 |
+
<div class="card">
|
| 41 |
+
<h3>Take Action</h3>
|
| 42 |
+
<input type="text" id="action" placeholder="e.g., change srv-1 to t3.small" style="width: 300px;">
|
| 43 |
+
<button class="btn" onclick="step()">Execute</button>
|
| 44 |
+
</div>
|
| 45 |
+
|
| 46 |
+
<div class="card">
|
| 47 |
+
<h3>Output</h3>
|
| 48 |
+
<div id="output">Select a task and click Reset to begin...</div>
|
| 49 |
+
</div>
|
| 50 |
|
| 51 |
+
<script>
|
| 52 |
+
let baseUrl = '';
|
| 53 |
+
|
| 54 |
+
async function resetEnv() {
|
| 55 |
+
const task = document.getElementById('task').value;
|
| 56 |
+
const res = await fetch('/reset?task=' + task);
|
| 57 |
+
const data = await res.json();
|
| 58 |
+
document.getElementById('output').textContent = JSON.stringify(data, null, 2);
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
async function step() {
|
| 62 |
+
const action = document.getElementById('action').value;
|
| 63 |
+
const res = await fetch('/step', {
|
| 64 |
+
method: 'POST',
|
| 65 |
+
headers: {'Content-Type': 'application/json'},
|
| 66 |
+
body: JSON.stringify({message: action})
|
| 67 |
+
});
|
| 68 |
+
const data = await res.json();
|
| 69 |
+
document.getElementById('output').textContent = JSON.stringify(data, null, 2);
|
| 70 |
+
}
|
| 71 |
+
</script>
|
| 72 |
+
</body>
|
| 73 |
+
</html>
|
| 74 |
+
"""
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
@app.get("/", response_class=HTMLResponse)
|
| 78 |
async def root():
|
| 79 |
+
return HTML_CONTENT
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
@app.get("/json")
|
| 83 |
+
async def api_info():
|
| 84 |
return {
|
| 85 |
"name": "CloudOps Optimizer",
|
| 86 |
"version": "1.0.0",
|