cloud450 commited on
Commit
66c2f76
·
verified ·
1 Parent(s): 1641937

Upload 3 files

Browse files
Files changed (3) hide show
  1. README.md +4 -6
  2. app.py +6 -15
  3. requirements.txt +0 -2
README.md CHANGED
@@ -4,7 +4,7 @@ emoji: 🕳️
4
  colorFrom: yellow
5
  colorTo: red
6
  sdk: gradio
7
- sdk_version: 4.42.0
8
  app_file: app.py
9
  pinned: false
10
  license: mit
@@ -59,7 +59,7 @@ The model was trained on a synthetically generated dataset of `10,000` samples d
59
 
60
  All features are min-max scaled `[0,1]`.
61
 
62
- ### Training Procedure
63
 
64
  - **Algorithm:** XGBoost
65
  - **Objective:** `reg:squarederror`
@@ -69,7 +69,7 @@ All features are min-max scaled `[0,1]`.
69
 
70
  ## 📊 Performance & Interpretability
71
 
72
- ### Model Metrics
73
  The model demonstrates high precision in predicting the severity score $S$, which controls civic resource allocation.
74
 
75
  | Metric | Value | Interpretation |
@@ -95,8 +95,6 @@ The bar chart below shows the mean absolute SHAP value, identifying which featur
95
  ![SHAP Bar Plot](shap_bar_plot.png)
96
 
97
  #### Detailed Impact (Beeswarm)
98
- The summary plot shows how high vs. low values of a feature affect out outcome. For example, high values of **C (Centrality)** push the score significantly higher.
99
 
100
  ![SHAP Dot Plot](shap_dot_plot.png)
101
-
102
- ## Training Details
 
4
  colorFrom: yellow
5
  colorTo: red
6
  sdk: gradio
7
+ sdk_version: 5.12.0
8
  app_file: app.py
9
  pinned: false
10
  license: mit
 
59
 
60
  All features are min-max scaled `[0,1]`.
61
 
62
+ ### Training Procedure
63
 
64
  - **Algorithm:** XGBoost
65
  - **Objective:** `reg:squarederror`
 
69
 
70
  ## 📊 Performance & Interpretability
71
 
72
+ ### Model Metrics
73
  The model demonstrates high precision in predicting the severity score $S$, which controls civic resource allocation.
74
 
75
  | Metric | Value | Interpretation |
 
95
  ![SHAP Bar Plot](shap_bar_plot.png)
96
 
97
  #### Detailed Impact (Beeswarm)
98
+ The summary plot shows how high vs. low values of a feature affect the outcome. For example, high values of **C (Centrality)** push the score significantly higher.
99
 
100
  ![SHAP Dot Plot](shap_dot_plot.png)
 
 
app.py CHANGED
@@ -1,22 +1,17 @@
1
  import sys
2
 
3
- # SHIM FOR PYTHON 3.13 TO FIX GRADIO/PYDUB "audioop" ERROR
4
- # This must happen before anything else is imported.
5
  try:
6
  import audioop
7
  except ImportError:
8
  import types
9
- # Fake the audioop module to satisfy pydub's import check
10
- module = types.ModuleType("audioop")
11
- sys.modules["audioop"] = module
12
- print("applied audioop shim for Python 3.13 compatibility")
13
 
14
  import gradio as gr
15
  import xgboost as xgb
16
  import joblib
17
  import json
18
  import numpy as np
19
- import os
20
 
21
  # --- Load Assets ---
22
  MODEL_PATH = "severity_model.json"
@@ -39,22 +34,18 @@ def get_label(score):
39
  return "High 🔴"
40
 
41
  def predict(*args):
42
- # Map arguments to feature list
43
  input_dict = dict(zip(feature_names, args))
44
  row = np.array([[input_dict[f] for f in feature_names]], dtype=np.float32)
45
-
46
- # Scale and predict
47
  scaled_row = scaler.transform(row)
48
  prediction = float(model.predict(scaled_row)[0])
49
  score = max(0, min(1, prediction))
50
-
51
  return round(score, 4), get_label(score)
52
 
53
- # --- UI Setup ---
54
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
55
  gr.Markdown("# 🕳️ Pothole Severity Predictor (Civic AI)")
56
  gr.Markdown("Adjust the sliders below to simulate pothole features and predict repair priority.")
57
-
58
  with gr.Row():
59
  with gr.Column():
60
  a = gr.Slider(0, 1, value=0.1, label="Area Ratio (A)", info="Size of pothole")
@@ -68,9 +59,9 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
68
  p = gr.Slider(0, 1, value=0.1, label="Critical Infra (P)", info="Proximity to hospitals/schools")
69
  f = gr.Slider(0, 1, value=0.1, label="Recurrence (F)", info="Historical failure")
70
  x = gr.Slider(0, 1, value=0.0, label="Reopen Count (X)", info="Failed repairs")
71
-
72
  btn = gr.Button("Calculate Severity Score", variant="primary")
73
-
74
  with gr.Row():
75
  out_score = gr.Number(label="Severity Score (0-1)")
76
  out_label = gr.Textbox(label="Priority Level")
 
1
  import sys
2
 
3
+ # SHIM FOR PYTHON 3.13: fake audioop module before any imports
 
4
  try:
5
  import audioop
6
  except ImportError:
7
  import types
8
+ sys.modules["audioop"] = types.ModuleType("audioop")
 
 
 
9
 
10
  import gradio as gr
11
  import xgboost as xgb
12
  import joblib
13
  import json
14
  import numpy as np
 
15
 
16
  # --- Load Assets ---
17
  MODEL_PATH = "severity_model.json"
 
34
  return "High 🔴"
35
 
36
  def predict(*args):
 
37
  input_dict = dict(zip(feature_names, args))
38
  row = np.array([[input_dict[f] for f in feature_names]], dtype=np.float32)
 
 
39
  scaled_row = scaler.transform(row)
40
  prediction = float(model.predict(scaled_row)[0])
41
  score = max(0, min(1, prediction))
 
42
  return round(score, 4), get_label(score)
43
 
44
+ # --- UI ---
45
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
46
  gr.Markdown("# 🕳️ Pothole Severity Predictor (Civic AI)")
47
  gr.Markdown("Adjust the sliders below to simulate pothole features and predict repair priority.")
48
+
49
  with gr.Row():
50
  with gr.Column():
51
  a = gr.Slider(0, 1, value=0.1, label="Area Ratio (A)", info="Size of pothole")
 
59
  p = gr.Slider(0, 1, value=0.1, label="Critical Infra (P)", info="Proximity to hospitals/schools")
60
  f = gr.Slider(0, 1, value=0.1, label="Recurrence (F)", info="Historical failure")
61
  x = gr.Slider(0, 1, value=0.0, label="Reopen Count (X)", info="Failed repairs")
62
+
63
  btn = gr.Button("Calculate Severity Score", variant="primary")
64
+
65
  with gr.Row():
66
  out_score = gr.Number(label="Severity Score (0-1)")
67
  out_label = gr.Textbox(label="Priority Level")
requirements.txt CHANGED
@@ -3,5 +3,3 @@ pandas
3
  scikit-learn
4
  xgboost
5
  joblib
6
- gradio
7
- huggingface_hub
 
3
  scikit-learn
4
  xgboost
5
  joblib