alidenewade commited on
Commit
9a2f907
Β·
verified Β·
1 Parent(s): 5ac174d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -8
app.py CHANGED
@@ -158,6 +158,13 @@ def predict_crime_level(crime_felony, crime_misd, crime_viol, sr311_total, dob_p
158
  """Predicts crime level based on input features."""
159
  print(f"DEBUG: predict_crime_level called with inputs: {crime_felony}, {crime_misd}, {crime_viol}, {sr311_total}, {dob_permits_total}")
160
 
 
 
 
 
 
 
 
161
  if model is None:
162
  # Create a dummy prediction based on simple logic when model is not available
163
  total_crime = crime_felony + crime_misd + crime_viol
@@ -183,9 +190,12 @@ def predict_crime_level(crime_felony, crime_misd, crime_viol, sr311_total, dob_p
183
  if dob_permits_total > 25:
184
  # High construction activity might indicate development/change
185
  confidence["Medium"] = min(0.8, confidence.get("Medium", 0) + 0.2)
186
-
187
- print(f"DEBUG: Dummy prediction result: {prediction}, confidence: {confidence}")
188
- return f"Predicted Crime Level: {prediction} (using fallback model)", confidence
 
 
 
189
 
190
  try:
191
  # The model expects many more features than we have available in this interface
@@ -222,19 +232,25 @@ def predict_crime_level(crime_felony, crime_misd, crime_viol, sr311_total, dob_p
222
  # Determine final prediction
223
  prediction = max(confidence.items(), key=lambda x: x[1])[0]
224
 
225
- print(f"DEBUG: Enhanced fallback prediction result: {prediction}, confidence: {confidence}")
226
- return f"Predicted Crime Level: {prediction} (enhanced model)", confidence
 
 
 
227
 
228
  except Exception as e:
229
  print(f"DEBUG: Error in model prediction: {e}")
230
  # Even if there's an error, provide a basic prediction
231
  total_crime = crime_felony + crime_misd + crime_viol
232
  if total_crime <= 20:
233
- return "Predicted Crime Level: Low (basic fallback)", {"Low": 0.6, "Medium": 0.3, "High": 0.1}
 
234
  elif total_crime <= 50:
235
- return "Predicted Crime Level: Medium (basic fallback)", {"Low": 0.2, "Medium": 0.6, "High": 0.2}
 
236
  else:
237
- return "Predicted Crime Level: High (basic fallback)", {"Low": 0.1, "Medium": 0.3, "High": 0.6}
 
238
 
239
  def forecast_time_series(geoid, selected_metric):
240
  """Forecasts crime for a specific GEOID."""
 
158
  """Predicts crime level based on input features."""
159
  print(f"DEBUG: predict_crime_level called with inputs: {crime_felony}, {crime_misd}, {crime_viol}, {sr311_total}, {dob_permits_total}")
160
 
161
+ # Define emoji mapping
162
+ emoji_map = {
163
+ "Low": "🟒",
164
+ "Medium": "🟑",
165
+ "High": "πŸ”΄"
166
+ }
167
+
168
  if model is None:
169
  # Create a dummy prediction based on simple logic when model is not available
170
  total_crime = crime_felony + crime_misd + crime_viol
 
190
  if dob_permits_total > 25:
191
  # High construction activity might indicate development/change
192
  confidence["Medium"] = min(0.8, confidence.get("Medium", 0) + 0.2)
193
+
194
+ # Add emojis to confidence labels
195
+ confidence_with_emojis = {f"{level} {emoji_map[level]}": prob for level, prob in confidence.items()}
196
+
197
+ print(f"DEBUG: Dummy prediction result: {prediction}, confidence: {confidence_with_emojis}")
198
+ return emoji_map[prediction], confidence_with_emojis
199
 
200
  try:
201
  # The model expects many more features than we have available in this interface
 
232
  # Determine final prediction
233
  prediction = max(confidence.items(), key=lambda x: x[1])[0]
234
 
235
+ # Add emojis to confidence labels
236
+ confidence_with_emojis = {f"{level} {emoji_map[level]}": prob for level, prob in confidence.items()}
237
+
238
+ print(f"DEBUG: Enhanced fallback prediction result: {prediction}, confidence: {confidence_with_emojis}")
239
+ return emoji_map[prediction], confidence_with_emojis
240
 
241
  except Exception as e:
242
  print(f"DEBUG: Error in model prediction: {e}")
243
  # Even if there's an error, provide a basic prediction
244
  total_crime = crime_felony + crime_misd + crime_viol
245
  if total_crime <= 20:
246
+ confidence = {"Low 🟒": 0.6, "Medium 🟑": 0.3, "High πŸ”΄": 0.1}
247
+ return "🟒", confidence
248
  elif total_crime <= 50:
249
+ confidence = {"Low 🟒": 0.2, "Medium 🟑": 0.6, "High πŸ”΄": 0.2}
250
+ return "🟑", confidence
251
  else:
252
+ confidence = {"Low 🟒": 0.1, "Medium 🟑": 0.3, "High πŸ”΄": 0.6}
253
+ return "πŸ”΄", confidence
254
 
255
  def forecast_time_series(geoid, selected_metric):
256
  """Forecasts crime for a specific GEOID."""