Spaces:
Sleeping
Sleeping
Update app_hf.py
Browse files10 unmodified lines1112131415161712 unmodified lines30313233343536373839404142434445464748491 unmodified line5152535455561 unmodified line58596061626364656667686915 unmodified lines8586878889909192939495969798991001011021031041051061071081091101111121131141151161171186 unmodified lines12512612712812913013113211 unmodified lines1441451461471481491501511521531543 unmodified lines15815916016116216316416516616716816917017117217317417517617717817918038 unmodified lines21922022122222322422510 unmodified lines)# -----------------------------------------------------------# JavaScript to switch themes by toggling body class# -----------------------------------------------------------theme_js = """12 unmodified lines"""# -----------------------------------------------------------# CSS FOR BOTH THEMES# -----------------------------------------------------------theme_css = """<style>/* Smooth transition */body, .gradio-container, * {transition: background-color .35s ease,color .35s ease,border .35s ease;}/* Default mode = light */body.light-mode {--bg: #ffffff;--text: #000000;1 unmodified line--border: #d0d0d0;}body.dark-mode {--bg: #0d1117;--text: #ffffff;1 unmodified line--border: #30363d;}body, .gradio-container {background-color: var(--bg) !important;color: var(--text) !important;}/* Floating Toggle Button */.theme-toggle {position: fixed;top: 16px;15 unmodified lines.theme-toggle:hover {transform: scale(1.15);box-shadow: 0 0 15px #58a6ff;}/* Card Styles */.card {background: var(--card-bg);border-radius: 12px;padding: 18px;margin-bottom: 20px;border: 1px solid var(--border);}/* Metric Boxes */.metric-box {background: var(--card-bg);padding: 16px;border-radius: 12px;border: 1px solid var(--border);margin-bottom: 14px;}/* Stats */.stat-card {background: var(--card-bg);padding: 18px;border-radius: 12px;border: 1px solid var(--border);text-align: center;}.stat-number {6 unmodified linesfont-size: 14px;opacity: 0.8;}</style>"""# -----------------------------------------------------------11 unmodified lineslr_r2 = metrics["train"]["r2_lr"]lr_rmse = metrics["train"]["rmse_lr"]with gr.Blocks(title="CPU Optimization Dashboard",) as demo:gr.HTML(f"<style>{custom_css}</style>")gr.HTML(f"<script>{theme_js}</script>")# Start in LIGHT MODEgr.HTML("<script>document.body.classList.add('light-mode');</script>")# Floating theme toggle button3 unmodified lines</div>""")gr.Markdown("# 🚀 CPU Optimization ML Dashboard")gr.Markdown("Real-time visualization of machine learning models")# MODEL SELECTORwith gr.Row():model_sel = gr.Dropdown(["Random Forest", "Linear Regression"],label="Select Model", value="Random Forest")model_out = gr.Markdown()def show_details(choice):if choice == "Random Forest":return f"### 🌳 Random Forest\n- R²: {rf_r2}\n- RMSE: {rf_rmse}"return f"### 📏 Linear Regression\n- R²: {lr_r2}\n- RMSE: {lr_rmse}"model_sel.change(show_details, model_sel, model_out)# ================== TABS ==================with gr.Tabs():# ===== Overview =====38 unmodified lines• R² = {rf_r2}<br>• RMSE = {rf_rmse}</div><div class='metric-box'><h4>📏 Linear Regression</h4>• R² = {lr_r2}<br>10 unmodified lines1112131415161712 unmodified lines3031323334353637383940414243444546471 unmodified line495051525354551 unmodified line5758596061626364656667686915 unmodified lines8586878889909192939495969798991001011021031041051061071081091101111121131141151161171181196 unmodified lines12612712812913013111 unmodified lines1431441451461471481491501511521531541553 unmodified lines15916016116216316416516616716816917017117238 unmodified lines21121221321421521610 unmodified lines)# -----------------------------------------------------------# JAVASCRIPT – Theme toggle# -----------------------------------------------------------theme_js = """12 unmodified lines"""# -----------------------------------------------------------# CSS – Both themes + toggle button + transitions# -----------------------------------------------------------theme_css = """/* Smooth transition */body, .gradio-container, * {transition: background-color .35s ease,color .35s ease,border-color .35s ease;}/* Light Theme */body.light-mode {--bg: #ffffff;--text: #000000;1 unmodified line--border: #d0d0d0;}/* Dark Theme */body.dark-mode {--bg: #0d1117;--text: #ffffff;1 unmodified line--border: #30363d;}/* Apply variables */body, .gradio-container {background-color: var(--bg) !important;color: var(--text) !important;}/* Floating theme toggle button */.theme-toggle {position: fixed;top: 16px;15 unmodified lines.theme-toggle:hover {transform: scale(1.15);box-shadow: 0 0 18px #58a6ff;}/* Cards */.card {background: var(--card-bg);border-radius: 12px;padding: 18px;border: 1px solid var(--border);margin-bottom: 20px;}/* Metric box */.metric-box {background: var(--card-bg);padding: 14px;border-radius: 12px;border: 1px solid var(--border);margin-bottom: 20px;}/* Stat cards */.stat-card {background: var(--card-bg);padding: 18px;border-radius: 12px;border: 1px solid var(--border);text-align: center;min-width: 160px;}.stat-number {6 unmodified linesfont-size: 14px;opacity: 0.8;}"""# -----------------------------------------------------------11 unmodified lineslr_r2 = metrics["train"]["r2_lr"]lr_rmse = metrics["train"]["rmse_lr"]with gr.Blocks(title="CPU Optimization Dashboard") as demo:# Inject styling + JSgr.HTML(f"<style>{theme_css}</style>")gr.HTML(f"<script>{theme_js}</script>")# Default to light modegr.HTML("<script>document.body.classList.add('light-mode');</script>")# Floating theme toggle button3 unmodified lines</div>""")# Headergr.Markdown("# 🚀 CPU Optimization ML Dashboard")gr.Markdown("Real-time visualization of machine learning model performance.")# ======================================================# 🧩 YOUR ORIGINAL TABS BLOCK (fixed + styled)# ======================================================with gr.Tabs():# ===== Overview =====38 unmodified lines• R² = {rf_r2}<br>• RMSE = {rf_rmse}</div><div class='metric-box'><h4>📏 Linear Regression</h4>• R² = {lr_r2}<br>
app_hf.py+26-35