Spaces:
Running
Running
Merge branch 'main' of https://github.com/LO-Kyu/gridmind
Browse filesFiles changed (6)
31 unmodified lines3233343536373839401 unmodified line4243444546471 unmodified line495051525354555657585960616263646531 unmodified linesCOPY data/ ./data/COPY openenv.yaml ./# Configure SupervisorRUN echo "[supervisord]" > /etc/supervisor/conf.d/supervisord.conf && \echo "nodaemon=true" >> /etc/supervisor/conf.d/supervisord.conf && \echo "[program:go-env]" >> /etc/supervisor/conf.d/supervisord.conf && \echo "command=/usr/local/bin/gridmind-server" >> /etc/supervisor/conf.d/supervisord.conf && \echo "environment=PORT=7860" >> /etc/supervisor/conf.d/supervisord.conf && \1 unmodified lineecho "stdout_logfile_maxbytes=0" >> /etc/supervisor/conf.d/supervisord.conf && \echo "stderr_logfile=/dev/stderr" >> /etc/supervisor/conf.d/supervisord.conf && \echo "stderr_logfile_maxbytes=0" >> /etc/supervisor/conf.d/supervisord.conf && \echo "[program:dashboard]" >> /etc/supervisor/conf.d/supervisord.conf && \echo "command=python -m uvicorn dashboard.server:app --host 0.0.0.0 --port 7861" >> /etc/supervisor/conf.d/supervisord.conf && \echo "stdout_logfile=/dev/stdout" >> /etc/supervisor/conf.d/supervisord.conf && \1 unmodified lineecho "stderr_logfile=/dev/stderr" >> /etc/supervisor/conf.d/supervisord.conf && \echo "stderr_logfile_maxbytes=0" >> /etc/supervisor/conf.d/supervisord.conf# Create run directory for supervisorRUN mkdir -p /var/run/supervisor /var/log/supervisor && \chmod 755 /var/run/supervisor /var/log/supervisor# Add a non-root user (good practice and required for some HF Spaces configs)RUN useradd -m -u 1000 user && \chown -R user:user /app && \chown -R user:user /var/run/supervisor /var/log/supervisor# 7860 = Env Server (main OpenEnv endpoint), 7861 = DashboardEXPOSE 7860 7861# Run supervisor as root to manage both services (required for multi-process supervision)CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf", "-n"]31 unmodified lines32333435363738394041424344451 unmodified line474849505152531 unmodified line5556575859606162636465666731 unmodified linesCOPY data/ ./data/COPY openenv.yaml ./# Configure Supervisor to use /tmp for socket and pid files (writable by any user)RUN echo "[unix_http_server]" > /etc/supervisor/conf.d/supervisord.conf && \echo "file=/tmp/supervisor.sock" >> /etc/supervisor/conf.d/supervisord.conf && \echo "" >> /etc/supervisor/conf.d/supervisord.conf && \echo "[supervisord]" >> /etc/supervisor/conf.d/supervisord.conf && \echo "pidfile=/tmp/supervisord.pid" >> /etc/supervisor/conf.d/supervisord.conf && \echo "nodaemon=true" >> /etc/supervisor/conf.d/supervisord.conf && \echo "" >> /etc/supervisor/conf.d/supervisord.conf && \echo "[program:go-env]" >> /etc/supervisor/conf.d/supervisord.conf && \echo "command=/usr/local/bin/gridmind-server" >> /etc/supervisor/conf.d/supervisord.conf && \echo "environment=PORT=7860" >> /etc/supervisor/conf.d/supervisord.conf && \1 unmodified lineecho "stdout_logfile_maxbytes=0" >> /etc/supervisor/conf.d/supervisord.conf && \echo "stderr_logfile=/dev/stderr" >> /etc/supervisor/conf.d/supervisord.conf && \echo "stderr_logfile_maxbytes=0" >> /etc/supervisor/conf.d/supervisord.conf && \echo "" >> /etc/supervisor/conf.d/supervisord.conf && \echo "[program:dashboard]" >> /etc/supervisor/conf.d/supervisord.conf && \echo "command=python -m uvicorn dashboard.server:app --host 0.0.0.0 --port 7861" >> /etc/supervisor/conf.d/supervisord.conf && \echo "stdout_logfile=/dev/stdout" >> /etc/supervisor/conf.d/supervisord.conf && \1 unmodified lineecho "stderr_logfile=/dev/stderr" >> /etc/supervisor/conf.d/supervisord.conf && \echo "stderr_logfile_maxbytes=0" >> /etc/supervisor/conf.d/supervisord.conf# EXPOSE 7860 only - this is the main OpenEnv API endpoint (reverse proxy + /dashboard)# Port 7861 (dashboard) runs internally only and is accessed via /dashboard proxyEXPOSE 7860# Add a non-root user (good practice and required for some HF Spaces configs)RUN useradd -m -u 1000 user && chown -R user:user /app# Run supervisord to manage both Go server and Python dashboard# Using /tmp for socket and pid files (writable by any user, including uid 1000)CMD ["supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
20 unmodified lines21222324252620 unmodified lines---## OverviewGridMind-RL is a reinforcement learning environment for training and evaluating intelligent control policies in industrial building energy management. The environment simulates realistic HVAC control, thermal storage management, batch job scheduling, and demand response scenarios under stochastic electricity pricing and grid stress events.20 unmodified lines21222324252627282930313233343536373839404120 unmodified lines------## 🚀 Live Demo| | URL ||--|-----|| **Environment API** | https://lo-kyu-gridmind.hf.space || **Live Dashboard** | https://lo-kyu-gridmind.hf.space/dashboard |**Quick test:**```bashcurl https://lo-kyu-gridmind.hf.space/healthcurl https://lo-kyu-gridmind.hf.space/tasks```## OverviewGridMind-RL is a reinforcement learning environment for training and evaluating intelligent control policies in industrial building energy management. The environment simulates realistic HVAC control, thermal storage management, batch job scheduling, and demand response scenarios under stochastic electricity pricing and grid stress events.
1234563 unmodified lines10111213141516/*** GridMind-RL Dashboard — Premium Chart.js real-time visualization* Polls /api/state every 500ms and updates all charts + KPIs.*/'use strict';3 unmodified linesconst EPISODE_STEPS = 96; // 24h × 4 steps/h (15-min)const HISTORY_LEN = EPISODE_STEPS;const CURVE_POINTS = 24; // hourly downsample (EpisodeSteps/4)const API_BASE = '/api';const TASK_NAMES = {1: 'Task 1 — Cost Minimization (Easy)',2: 'Task 2 — Temperature Management (Medium)',1234563 unmodified lines10111213141516/*** GridMind-RL Dashboard — Premium Chart.js real-time visualization* Polls /dashboard/api/state every 500ms and updates all charts + KPIs.*/'use strict';3 unmodified linesconst EPISODE_STEPS = 96; // 24h × 4 steps/h (15-min)const HISTORY_LEN = EPISODE_STEPS;const CURVE_POINTS = 24; // hourly downsample (EpisodeSteps/4)const API_BASE = '/dashboard/api';const TASK_NAMES = {1: 'Task 1 — Cost Minimization (Easy)',2: 'Task 2 — Temperature Management (Medium)',
1034 unmodified lines10351036103710381039104010415 unmodified lines10471048104910501051105210531054105510561034 unmodified lines<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/><line x1="16" y1="13" x2="8" y2="13"/><line x1="16" y1="17" x2="8" y2="17"/></svg>Grade Episode</button><button class="btn" onclick="window.open('/api/replay')"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>Export Replay</button>5 unmodified lines<footer>GridMind-RL · OpenEnv-compliant RL environment for industrial demand response · <a href="/api/health" target="_blank">API Health</a> · <a href="/api/metrics" target="_blank">Metrics</a></footer><script src="/static/dashboard.js"></script></body></html>1034 unmodified lines10351036103710381039104010415 unmodified lines10471048104910501051105210531054105510561034 unmodified lines<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/><line x1="16" y1="13" x2="8" y2="13"/><line x1="16" y1="17" x2="8" y2="17"/></svg>Grade Episode</button><button class="btn" onclick="window.open('/dashboard/api/replay')"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>Export Replay</button>5 unmodified lines<footer>GridMind-RL · OpenEnv-compliant RL environment for industrial demand response · <a href="/dashboard/api/health" target="_blank">API Health</a> · <a href="/dashboard/api/metrics" target="_blank">Metrics</a></footer><script src="/dashboard/static/dashboard.js"></script></body></html>
7 unmodified lines891011121314151615 unmodified lines323334353637383994 unmodified lines1341351361371381393 unmodified lines143144145146147148149150151181 unmodified lines33333433533633733815 unmodified lines3543553563573583593607 unmodified lines"fmt""log""math""net/http""os""strconv""sync""sync/atomic""time"15 unmodified linesrewardMin float64rewardMax float64// HistogramsactionBuckets map[string]int64 // hvac bucket countserrorCount int64}var metrics = &Metrics{94 unmodified linesfunc (s *Server) routes() *http.ServeMux {mux := http.NewServeMux()mux.HandleFunc("/health", s.handleHealth)mux.HandleFunc("/ping", s.handlePing)mux.HandleFunc("/reset", s.handleReset)3 unmodified linesmux.HandleFunc("/grade", s.handleGrade)mux.HandleFunc("/tasks", s.handleTasks)mux.HandleFunc("/metrics", s.handleMetrics)return mux}// ── /health ──────────────────────────────────────────────────────────────────func (s *Server) handleHealth(w http.ResponseWriter, r *http.Request) {181 unmodified linesfmt.Fprint(w, metrics.prometheus())}// ──────────────────────────────────────────────// Entry point// ──────────────────────────────────────────────15 unmodified linessrv.envMgr.Reset(env.ResetRequest{Seed: &seed, TaskID: 1, NumBuildings: 1})log.Printf("GridMind-RL environment server starting on :%s", port)log.Printf("Endpoints: GET /health /ping /state /replay /grade /tasks /metrics | POST /reset /step")mux := withCORS(withLogging(srv.routes()))if err := http.ListenAndServe(":"+port, mux); err != nil {7 unmodified lines89101112131415161718192015 unmodified lines363738394041424394 unmodified lines1381391401411421431443 unmodified lines148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210181 unmodified lines39239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844915 unmodified lines4654664674684694704717 unmodified lines"fmt""log""math""net""net/http""net/http/httputil""net/url""os""strconv""strings""sync""sync/atomic""time"15 unmodified linesrewardMin float64rewardMax float64// HistogramsactionBuckets map[string]int64 // hvac bucket countserrorCount int64}var metrics = &Metrics{94 unmodified linesfunc (s *Server) routes() *http.ServeMux {mux := http.NewServeMux()mux.HandleFunc("/", s.handleRoot)mux.HandleFunc("/health", s.handleHealth)mux.HandleFunc("/ping", s.handlePing)mux.HandleFunc("/reset", s.handleReset)3 unmodified linesmux.HandleFunc("/grade", s.handleGrade)mux.HandleFunc("/tasks", s.handleTasks)mux.HandleFunc("/metrics", s.handleMetrics)// Reverse proxy for dashboard (runs on port 7861 internally)mux.HandleFunc("/dashboard", s.handleDashboardProxy)mux.HandleFunc("/dashboard/", s.handleDashboardProxy)return mux}// ── / (Root) ────────────────────────────────────────────────────────────────func (s *Server) handleRoot(w http.ResponseWriter, r *http.Request) {if r.URL.Path != "/" {http.NotFound(w, r)return}w.Header().Set("Content-Type", "text/html; charset=utf-8")html := `<!DOCTYPE html><html><head><title>GridMind-RL</title><style>body { font-family: monospace; background: #0d1117; color: #e6edf3; padding: 40px; }a { color: #58a6ff; text-decoration: none; }a:hover { text-decoration: underline; }.badge { background: #238636; padding: 4px 10px; border-radius: 4px; color: white; display: inline-block; }ul { line-height: 1.8; }pre { background: #0d1117; border: 1px solid #30363d; padding: 16px; border-radius: 6px; overflow-x: auto; }</style></head><body><h1>⚡ GridMind-RL</h1><p><span class="badge">● RUNNING</span></p><p>Industrial building energy management RL environment — OpenEnv compliant.</p><h3>🔗 Quick Links</h3><ul><li><a href="/dashboard">→ Live Dashboard</a></li><li><a href="/health">→ API Health Check</a></li><li><a href="/tasks">→ Available Tasks</a></li><li><a href="/metrics">→ Prometheus Metrics</a></li></ul><h3>📡 API Endpoints</h3><pre>GET /health → health checkGET /ping → ping pongGET /state → current environment stateGET /replay → episode replay dataGET /grade → episode grade scoreGET /tasks → list of tasksGET /metrics → prometheus metricsPOST /reset {task_id} → start new episodePOST /step {action} → take action</pre><h3>📚 Links</h3><ul><li><a href="https://github.com/LO-Kyu/gridmind">GitHub Repository</a></li><li><a href="https://openenv.org">OpenEnv Specification</a></li></ul></body></html>`w.Write([]byte(html))}// ── /health ──────────────────────────────────────────────────────────────────func (s *Server) handleHealth(w http.ResponseWriter, r *http.Request) {181 unmodified linesfmt.Fprint(w, metrics.prometheus())}// ── /dashboard (Reverse Proxy) ────────────────────────────────────────────func (s *Server) handleDashboardProxy(w http.ResponseWriter, r *http.Request) {// Target URL for the dashboard service (running on localhost:7861)target, err := url.Parse("http://localhost:7861")if err != nil {http.Error(w, "proxy configuration error", http.StatusInternalServerError)return}// Create a custom director to modify the requestdirector := func(req *http.Request) {// Strip /dashboard prefixpath := req.URL.Pathif strings.HasPrefix(path, "/dashboard") {path = strings.TrimPrefix(path, "/dashboard")if path == "" {path = "/"}}// Set up the new requestreq.URL.Scheme = target.Schemereq.URL.Host = target.Hostif target.Path != "" {req.URL.Path = target.Path + path} else {req.URL.Path = path}req.RequestURI = ""// Preserve original host header for dashboard API callsif req.Header.Get("X-Forwarded-Host") == "" {req.Header.Set("X-Forwarded-For", getClientIP(r))req.Header.Set("X-Forwarded-Proto", "https")}}// Use ReverseProxy with custom directorproxy := &httputil.ReverseProxy{Director: director}proxy.ServeHTTP(w, r)}// Helper: extract client IP from requestfunc getClientIP(r *http.Request) string {ip, _, err := net.SplitHostPort(r.RemoteAddr)if err != nil {return r.RemoteAddr}return ip}// ──────────────────────────────────────────────// Entry point// ──────────────────────────────────────────────15 unmodified linessrv.envMgr.Reset(env.ResetRequest{Seed: &seed, TaskID: 1, NumBuildings: 1})log.Printf("GridMind-RL environment server starting on :%s", port)log.Printf("Endpoints: GET / (landing) | GET /health /ping /state /replay /grade /tasks /metrics /dashboard | POST /reset /step")mux := withCORS(withLogging(srv.routes()))if err := http.ListenAndServe(":"+port, mux); err != nil {
375 unmodified lines376377378379380381375 unmodified linesgrade = env_client.grade()# Emit [END] with required fieldsprint(f"[END] success={'true' if success else 'false'} steps={total_steps} rewards={rewards_str}",flush=True375 unmodified lines376377378379380381382383375 unmodified linesgrade = env_client.grade()# Emit [END] with required fieldssuccess = last_error is None and step_resp.get("done", False)rewards_str = ",".join(f"{r:.2f}" for r in step_rewards)print(f"[END] success={'true' if success else 'false'} steps={total_steps} rewards={rewards_str}",flush=True
Dockerfile+15-13
README.md+15
dashboard/static/dashboard.js+2-2
dashboard/static/index.html+4-4
main.go+114-3
python/inference.py+2