sharktide commited on
Commit
79f38e2
·
verified ·
1 Parent(s): ab4c89f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +126 -0
app.py CHANGED
@@ -174,6 +174,31 @@ def predict_hurricane(sst, ohc, mlh, vws, pv, sstu, use_trust):
174
  else:
175
  return f"🛡️ Hurricane Unlikely ({adjusted:.2f})"
176
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
177
  def generate_plot(axis, use_trustnet):
178
  sweep_values = np.linspace({
179
  "temperature": (280, 320),
@@ -438,6 +463,47 @@ def generate_hurricane_plot(axis, use_trustnet):
438
  return fig
439
 
440
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
441
  with gr.Blocks(theme=gr.themes.Default(), css=".tab-nav-button { font-size: 1.1rem !important; padding: 0.8em; } ") as demo:
442
  gr.Markdown("### STRIKE: A High-Precision AI Framework for Early Prediction of Natural Diasters")
443
  gr.Markdown("##### Preview")
@@ -815,6 +881,66 @@ with gr.Blocks(theme=gr.themes.Default(), css=".tab-nav-button { font-size: 1.1r
815
  outputs=[hurricane_output, hurricane_plot]
816
  )
817
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
818
 
819
  app = FastAPI()
820
 
 
174
  else:
175
  return f"🛡️ Hurricane Unlikely ({adjusted:.2f})"
176
 
177
+ def predict_tornado(srh, cape, lcl, shear, stp, use_trustnet):
178
+ features = [srh, cape, lcl, shear, stp]
179
+ raw = np.array(features, dtype="float32").reshape(1, -1)
180
+
181
+ base_pred = TornadoNet(raw).numpy()[0][0]
182
+ verdict = None
183
+
184
+ if use_trustnet:
185
+ scaled = TornadoTrustScaler.transform(pd.DataFrame([features], columns=[
186
+ "storm_relative_helicity", "CAPE",
187
+ "lifted_condensation_level", "bulk_wind_shear",
188
+ "significant_tornado_param"
189
+ ]))
190
+ trust_score = TornadoTrustNet(scaled).numpy()[0][0]
191
+ adjusted = np.clip(base_pred * trust_score, 0, 1)
192
+ else:
193
+ adjusted = base_pred
194
+
195
+ if adjusted > 0.55:
196
+ return f"🌪️ TORNADO LIKELY ({adjusted:.2f})"
197
+ elif 0.40 < adjusted <= 0.55:
198
+ return f"⚠️ Tornado Possible ({adjusted:.2f})"
199
+ else:
200
+ return f"🛡️ Tornado Unlikely ({adjusted:.2f})"
201
+
202
  def generate_plot(axis, use_trustnet):
203
  sweep_values = np.linspace({
204
  "temperature": (280, 320),
 
463
  return fig
464
 
465
 
466
+ def generate_tornado_plot(axis, use_trustnet):
467
+ axis_ranges = {
468
+ "storm_relative_helicity": (100, 500),
469
+ "CAPE": (0, 4000),
470
+ "lifted_condensation_level": (300, 2000),
471
+ "bulk_wind_shear": (0, 30),
472
+ "significant_tornado_param": (0.0, 5.0)
473
+ }
474
+
475
+ sweep_values = np.linspace(*axis_ranges[axis], 100)
476
+
477
+ base_input = {
478
+ "storm_relative_helicity": 280,
479
+ "CAPE": 3000,
480
+ "lifted_condensation_level": 950,
481
+ "bulk_wind_shear": 12,
482
+ "significant_tornado_param": 1.8
483
+ }
484
+
485
+ df = pd.DataFrame([{**base_input, axis: val} for val in sweep_values])
486
+ raw_preds = TornadoNet.predict(df).flatten()
487
+
488
+ if use_trustnet:
489
+ scaled_df = TornadoTrustScaler.transform(df)
490
+ trust_scores = TornadoTrustNet.predict(scaled_df).flatten()
491
+ modulated = np.clip(raw_preds * trust_scores, 0, 1)
492
+ else:
493
+ modulated = raw_preds
494
+
495
+ fig, ax = plt.subplots()
496
+ ax.plot(sweep_values, raw_preds, "--", color="gray", label="TornadoNet")
497
+ if use_trustnet:
498
+ ax.plot(sweep_values, modulated, color="darkred", label="Trust-Modulated")
499
+ ax.set_xlabel(axis.replace("_", " ").title())
500
+ ax.set_ylabel("Tornado Likelihood")
501
+ ax.set_title(f"Tornado Formation vs. {axis.replace('_', ' ').title()}")
502
+ ax.legend()
503
+ ax.grid(True)
504
+
505
+ return fig
506
+
507
  with gr.Blocks(theme=gr.themes.Default(), css=".tab-nav-button { font-size: 1.1rem !important; padding: 0.8em; } ") as demo:
508
  gr.Markdown("### STRIKE: A High-Precision AI Framework for Early Prediction of Natural Diasters")
509
  gr.Markdown("##### Preview")
 
881
  outputs=[hurricane_output, hurricane_plot]
882
  )
883
 
884
+ with gr.Tab("🌪️ Tornadoes"):
885
+ with gr.Row():
886
+ with gr.Column():
887
+ with gr.Row():
888
+ srh_input = gr.Slider(100, 500, value=280, label="Storm Relative Helicity (SRH, 0–3 km) [m²/s²]")
889
+ gr.Dropdown(["m²/s²"], value="m²/s²", label="", scale=0.2)
890
+
891
+ with gr.Row():
892
+ cape_input = gr.Slider(0, 4000, value=3000, label="Convective Available Potential Energy (CAPE) [J/kg]")
893
+ gr.Dropdown(["J/kg"], value="J/kg", label="", scale=0.2)
894
+
895
+ with gr.Row():
896
+ lcl_input = gr.Slider(300, 2000, value=950, label="Lifted Condensation Level (LCL) [m]")
897
+ gr.Dropdown(["m"], value="m", label="", scale=0.2)
898
+
899
+ with gr.Row():
900
+ shear_input = gr.Slider(0, 30, value=12, label="0–6 km Bulk Wind Shear [m/s]")
901
+ gr.Dropdown(["m/s"], value="m/s", label="", scale=0.2)
902
+
903
+ with gr.Row():
904
+ stp_input = gr.Slider(0.0, 5.0, value=1.8, label="Significant Tornado Parameter (STP)")
905
+ gr.Dropdown(["unitless"], value="unitless", label="", scale=0.2)
906
+
907
+ use_trust_tornado = gr.Checkbox(label="Use TornadoTrustNet", value=True)
908
+
909
+ tornado_sweep_axis = gr.Radio(
910
+ ["storm_relative_helicity", "CAPE", "lifted_condensation_level", "bulk_wind_shear", "significant_tornado_param"],
911
+ label="Sweep Axis", value="CAPE"
912
+ )
913
+
914
+ tornado_predict_btn = gr.Button("Predict")
915
+
916
+ with gr.Column():
917
+ with gr.Accordion("ℹ️ Feature Definitions", open=False):
918
+ gr.Markdown("""
919
+ **SRH (m²/s²):** Measures potential for rotating updrafts.
920
+
921
+ **CAPE (J/kg):** Buoyant energy available for strong vertical motion.
922
+
923
+ **LCL (m):** Lower values favor low-level vortex development.
924
+
925
+ **Bulk Wind Shear (m/s):** Higher values improve storm structure.
926
+
927
+ **STP (unitless):** Composite index for tornado likelihood.
928
+ """)
929
+
930
+ tornado_output = gr.Textbox(label="Tornado Formation Verdict")
931
+ tornado_plot = gr.Plot(label="Trust-Modulated Tornado Risk")
932
+
933
+ tornado_predict_btn.click(
934
+ fn=lambda srh, cape, lcl, shear, stp, trust, axis: (
935
+ predict_tornado(srh, cape, lcl, shear, stp, trust),
936
+ generate_tornado_plot(axis, trust)
937
+ ),
938
+ inputs=[
939
+ srh_input, cape_input, lcl_input, shear_input, stp_input,
940
+ use_trust_tornado, tornado_sweep_axis
941
+ ],
942
+ outputs=[tornado_output, tornado_plot]
943
+ )
944
 
945
  app = FastAPI()
946