Spaces:
Sleeping
Sleeping
Update app.py
Browse files33 unmodified lines343536373839404121 unmodified lines6364656667686970716 unmodified lines7879808182838418 unmodified lines1031041051061071081093 unmodified lines11311411511611711811933 unmodified linesprediction = model.predict(input_data)[0]# --- Create Interactive Gauge Chart ---# The bar turns red if it crosses 2006, otherwise it's green.bar_color = "red" if prediction >= 2006 else "#00cc66"fig = go.Figure(go.Indicator(mode = "gauge+number",21 unmodified linesfig.update_layout(height=350, margin=dict(l=20, r=20, t=50, b=20))# --- Generate Warnings ---warning_text = "β System Optimized.\nBattery usage is in a healthy range. No action required."if prediction >= 2006:# Pick random apps to stopapps_string = ", ".join(random.sample(APP_LIST, k=random.randint(3, 4)))6 unmodified linesreturn fig, warning_text# 3. Build a Clean, Modern UI# Using the "Ocean" theme for a sleek tech aestheticwith gr.Blocks(theme=gr.themes.Ocean()) as app:gr.Markdown("# π Mobile Battery Drain Predictor Dashboard")18 unmodified lineswarning_output = gr.Textbox(label="System Status", lines=6)# --- Live Interactivity ---# Instead of a submit button, we link every input to update the output INSTANTLY when dragged!inputs_list = [screen_time_input, app_time_input, apps_installed_input, data_usage_input, age_input, device_input]for input_element in inputs_list:3 unmodified linesoutputs=[gauge_output, warning_output])# Run once on startup so the chart isn't empty when the app loadsapp.load(fn=predict_and_plot,inputs=inputs_list,33 unmodified lines343536373839404121 unmodified lines63646566676869707172736 unmodified lines80818283848518 unmodified lines1041051061071081093 unmodified lines11311411511611711811933 unmodified linesprediction = model.predict(input_data)[0]# --- Create Interactive Gauge Chart ---# CHANGED: Now only turns red if strictly GREATER than 2006bar_color = "red" if prediction > 2006 else "#00cc66"fig = go.Figure(go.Indicator(mode = "gauge+number",21 unmodified linesfig.update_layout(height=350, margin=dict(l=20, r=20, t=50, b=20))# --- Generate Warnings ---# Default state (Do nothing / Safe state)warning_text = "β System Optimized.\nBattery usage is in a healthy range. No action required."# CHANGED LOGIC: If strictly greater than 2006, trigger warningsif prediction > 2006:# Pick random apps to stopapps_string = ", ".join(random.sample(APP_LIST, k=random.randint(3, 4)))6 unmodified linesreturn fig, warning_text# 3. Build a Clean, Modern UIwith gr.Blocks(theme=gr.themes.Ocean()) as app:gr.Markdown("# π Mobile Battery Drain Predictor Dashboard")18 unmodified lineswarning_output = gr.Textbox(label="System Status", lines=6)# --- Live Interactivity ---inputs_list = [screen_time_input, app_time_input, apps_installed_input, data_usage_input, age_input, device_input]for input_element in inputs_list:3 unmodified linesoutputs=[gauge_output, warning_output])# Run once on startupapp.load(fn=predict_and_plot,inputs=inputs_list,
app.py+6-6