""" Hugging Face Spaces Deployment Entry Point Lightweight dashboard entry point without heavy dependencies """ import os import sys # Set up environment os.environ['GRADIO_SERVER_NAME'] = '0.0.0.0' os.environ['GRADIO_SERVER_PORT'] = '7860' # Import Gradio import gradio as gr from dashboard_simple import ( load_metrics, get_summary_info, create_comparison_charts, format_metrics_text, get_artifacts_info ) # ----------- CSS (works on all Gradio versions) ----------- custom_css = """ """ if __name__ == "__main__": metrics = load_metrics() r2_chart, rmse_chart = create_comparison_charts(metrics) artifacts = get_artifacts_info() rf_r2 = metrics.get('train', {}).get('r2_rf', 'N/A') rf_rmse = metrics.get('train', {}).get('rmse_rf', 'N/A') lr_r2 = metrics.get('train', {}).get('r2_lr', 'N/A') lr_rmse = metrics.get('train', {}).get('rmse_lr', 'N/A') # Dropdown logic def show_model_details(choice): if choice == "Random Forest": return f"### 🌳 Random Forest Selected\n- R² Score: {rf_r2}\n- RMSE: {rf_rmse}" else: return f"### 📏 Linear Regression Selected\n- R² Score: {lr_r2}\n- RMSE: {lr_rmse}" # ----------- FIXED: No css= argument ----------- with gr.Blocks(title="CPU Optimization Dashboard") as demo: # Inject CSS safely gr.HTML(custom_css) gr.HTML("

🚀 CPU Optimization ML Dashboard

") gr.Markdown("Real-time visualization of machine learning models for CPU usage prediction") # ------------ DROPDOWN ------------ with gr.Row(): model_selector = gr.Dropdown( ["Random Forest", "Linear Regression"], label="Select Model", value="Random Forest" ) model_output = gr.Markdown() model_selector.change(show_model_details, inputs=model_selector, outputs=model_output) # ---------------------- TABS ---------------------- with gr.Tabs(): with gr.Tab("📋 Overview"): gr.HTML(f"""

Dashboard Overview

✓ Dashboard is running and all models are loaded successfully

Key Metrics

Quick Stats

""") # COMPARISON with gr.Tab("📈 Comparison"): gr.Markdown(f"""

Model Performance Comparison

Random Forest:
R² = {rf_r2}, RMSE = {rf_rmse}

Linear Regression:
R² = {lr_r2}, RMSE = {lr_rmse}

🎯 Winner: Random Forest 🏆

- ✓ Higher R² Score - ✓ Lower RMSE
""") gr.HTML(r2_chart) gr.HTML(rmse_chart) # METRICS with gr.Tab("📊 Metrics"): gr.Markdown(f"""

Model Metrics Detail

🌳 Random Forest

- R² Score: {rf_r2}
- RMSE: {rf_rmse}
- Model Type: Ensemble (100 trees)
- Performance: Excellent

📏 Linear Regression

- R² Score: {lr_r2}
- RMSE: {lr_rmse}
- Model Type: Linear (Baseline)
- Performance: Baseline
""") # ARTIFACTS with gr.Tab("📦 Artifacts"): gr.Markdown(f"
\n

Model Artifacts

\n{artifacts}\n
") # INFO with gr.Tab("ℹ️ Information"): gr.Markdown("""

System Information

Dashboard Configuration
- Dashboard Version: 2.0.0 - Gradio Version: 3.50.0 - Python Version: 3.11+ - Deployment: Hugging Face Spaces
Deployment Ready
- ✓ Works in HF Spaces - ✓ Docker Compatible - ✓ Cloud-Deployable
""") gr.Markdown("---") gr.Markdown("**CPU Optimization ML Dashboard** | Built with Gradio & Scikit-learn") demo.launch(server_name="0.0.0.0", server_port=7860, share=False)