Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -150,6 +150,30 @@ def predict_quake(dotM0, sdr, coulomb, afd, fsr, use_trust):
|
|
| 150 |
else:
|
| 151 |
return f"🛡️ Earthquake Unlikely ({adjusted:.2f})"
|
| 152 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
def generate_plot(axis, use_trustnet):
|
| 154 |
sweep_values = np.linspace({
|
| 155 |
"temperature": (280, 320),
|
|
@@ -370,6 +394,49 @@ def generate_quake_plot(axis, use_trustnet):
|
|
| 370 |
|
| 371 |
return fig
|
| 372 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 373 |
|
| 374 |
with gr.Blocks(theme=gr.themes.Default(), css=".tab-nav-button { font-size: 1.1rem !important; padding: 0.8em; } ") as demo:
|
| 375 |
gr.Markdown("### STRIKE: A High-Precision AI Framework for Early Prediction of Natural Diasters")
|
|
@@ -685,6 +752,70 @@ with gr.Blocks(theme=gr.themes.Default(), css=".tab-nav-button { font-size: 1.1r
|
|
| 685 |
outputs=[quake_output, quake_plot]
|
| 686 |
)
|
| 687 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 688 |
app = FastAPI()
|
| 689 |
|
| 690 |
app.add_middleware(
|
|
|
|
| 150 |
else:
|
| 151 |
return f"🛡️ Earthquake Unlikely ({adjusted:.2f})"
|
| 152 |
|
| 153 |
+
def predict_hurricane(sst, ohc, mlh, vws, pv, sstu, use_trust):
|
| 154 |
+
sst = convert_temp_c(value=sst, unit=sstu)
|
| 155 |
+
input_data = {
|
| 156 |
+
"sea_surface_temperature": sst,
|
| 157 |
+
"ocean_heat_content": ohc,
|
| 158 |
+
"mid_level_humidity": mlh,
|
| 159 |
+
"vertical_wind_shear": vws,
|
| 160 |
+
"potential_vorticity": pv
|
| 161 |
+
}
|
| 162 |
+
input_df = pd.DataFrame([input_data])
|
| 163 |
+
base_pred = HurricaneNet.predict(input_df)[0][0]
|
| 164 |
+
if use_trust:
|
| 165 |
+
trust_score = HurricaneTrustNet.predict(HurricaneTrustScaler.transform(input_df))[0][0]
|
| 166 |
+
adjusted = np.clip(base_pred * trust_score, 0, 1)
|
| 167 |
+
else:
|
| 168 |
+
adjusted = base_pred
|
| 169 |
+
|
| 170 |
+
if adjusted > 0.55:
|
| 171 |
+
return f"🌀 HURRICANE LIKELY ({adjusted:.2f})"
|
| 172 |
+
elif 0.40 < adjusted <= 0.55:
|
| 173 |
+
return f"⚠️ Hurricane Possible ({adjusted:.2f})"
|
| 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),
|
|
|
|
| 394 |
|
| 395 |
return fig
|
| 396 |
|
| 397 |
+
def generate_hurricane_plot(axis, use_trustnet):
|
| 398 |
+
|
| 399 |
+
axis_ranges = {
|
| 400 |
+
"sea_surface_temperature": (24, 32),
|
| 401 |
+
"ocean_heat_content": (20, 150),
|
| 402 |
+
"mid_level_humidity": (20, 100),
|
| 403 |
+
"vertical_wind_shear": (0, 30),
|
| 404 |
+
"potential_vorticity": (0.0, 3.0)
|
| 405 |
+
}
|
| 406 |
+
|
| 407 |
+
sweep_values = np.linspace(*axis_ranges[axis], 100)
|
| 408 |
+
|
| 409 |
+
base_input = {
|
| 410 |
+
"sea_surface_temperature": 29.0,
|
| 411 |
+
"ocean_heat_content": 95,
|
| 412 |
+
"mid_level_humidity": 65,
|
| 413 |
+
"vertical_wind_shear": 9,
|
| 414 |
+
"potential_vorticity": 1.2
|
| 415 |
+
}
|
| 416 |
+
|
| 417 |
+
df = pd.DataFrame([{**base_input, axis: val} for val in sweep_values])
|
| 418 |
+
raw_preds = HurricaneNet.predict(df).flatten()
|
| 419 |
+
|
| 420 |
+
if use_trustnet:
|
| 421 |
+
scaled_df = HurricaneTrustScaler.transform(df)
|
| 422 |
+
trust_scores = HurricaneTrustNet.predict(scaled_df).flatten()
|
| 423 |
+
modulated = np.clip(raw_preds * trust_scores, 0, 1)
|
| 424 |
+
else:
|
| 425 |
+
modulated = raw_preds
|
| 426 |
+
|
| 427 |
+
# Plot
|
| 428 |
+
fig, ax = plt.subplots()
|
| 429 |
+
ax.plot(sweep_values, raw_preds, "--", color="gray", label="HurricaneNet")
|
| 430 |
+
if use_trustnet:
|
| 431 |
+
ax.plot(sweep_values, modulated, color="navy", label="Trust-Modulated")
|
| 432 |
+
ax.set_xlabel(axis.replace("_", " ").title())
|
| 433 |
+
ax.set_ylabel("Formation Likelihood")
|
| 434 |
+
ax.set_title(f"Hurricane Formation vs. {axis.replace('_', ' ').title()}")
|
| 435 |
+
ax.legend()
|
| 436 |
+
ax.grid(True)
|
| 437 |
+
|
| 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")
|
|
|
|
| 752 |
outputs=[quake_output, quake_plot]
|
| 753 |
)
|
| 754 |
|
| 755 |
+
with gr.Tab("🌀 Hurricanes"):
|
| 756 |
+
with gr.Row():
|
| 757 |
+
with gr.Column():
|
| 758 |
+
with gr.Row():
|
| 759 |
+
sst_input = gr.Slider(40, 140, value=80.0, label="Sea Surface Temperature (°C)")
|
| 760 |
+
sst_unit = gr.Dropdown(["°C", "°F"], value="°F", label="", scale=0.2)
|
| 761 |
+
sst_unit.change(update_temp_slider, inputs=sst_unit, outputs=sst_input)
|
| 762 |
+
with gr.Row():
|
| 763 |
+
ohc_input = gr.Slider(20, 150, value=95, label="Ocean Heat Content (kJ/cm²)")
|
| 764 |
+
gr.Dropdown(["kJ/cm²"], value="kJ/cm²", label="", scale=0.2)
|
| 765 |
+
|
| 766 |
+
with gr.Row():
|
| 767 |
+
humidity_input = gr.Slider(20, 100, value=65, label="Mid-Level Relative Humidity (%)")
|
| 768 |
+
gr.Dropdown(["%"], value="%", label="", scale=0.2)
|
| 769 |
+
|
| 770 |
+
with gr.Row():
|
| 771 |
+
shear_input = gr.Slider(0, 30, value=9, label="Vertical Wind Shear (m/s)")
|
| 772 |
+
gr.Dropdown(["m/s"], value="m/s", label="", scale=0.2)
|
| 773 |
+
|
| 774 |
+
with gr.Row():
|
| 775 |
+
vort_input = gr.Slider(0.0, 3.0, value=1.2, label="Potential Vorticity (PVU)")
|
| 776 |
+
gr.Dropdown(["PVU"], value="PVU", label="", scale=0.2)
|
| 777 |
+
|
| 778 |
+
use_trust_cyclone = gr.Checkbox(label="Use HurricaneTrustNet", value=True)
|
| 779 |
+
|
| 780 |
+
hurricane_sweep_axis = gr.Radio(
|
| 781 |
+
["sea_surface_temperature", "ocean_heat_content",
|
| 782 |
+
"mid_level_humidity", "vertical_wind_shear", "potential_vorticity"],
|
| 783 |
+
label="Sweep Axis", value="sea_surface_temperature"
|
| 784 |
+
)
|
| 785 |
+
|
| 786 |
+
hurricane_predict_btn = gr.Button("Predict")
|
| 787 |
+
|
| 788 |
+
with gr.Column():
|
| 789 |
+
with gr.Accordion("ℹ️ Feature Definitions", open=False):
|
| 790 |
+
gr.Markdown("""
|
| 791 |
+
**Sea Surface Temperature (°C):** Thermal fuel for cyclone formation.
|
| 792 |
+
|
| 793 |
+
**Ocean Heat Content (kJ/cm²):** Depth-integrated ocean energy — sustains storm growth.
|
| 794 |
+
|
| 795 |
+
**Mid-Level Relative Humidity (%):** Moisture around 500 hPa — supports convective core.
|
| 796 |
+
|
| 797 |
+
**Vertical Wind Shear (m/s):** Disrupts vertical structure — high values inhibit intensification.
|
| 798 |
+
|
| 799 |
+
**Potential Vorticity (PVU):** Atmospheric spin and structure — higher values favor formation.
|
| 800 |
+
""")
|
| 801 |
+
|
| 802 |
+
hurricane_output = gr.Textbox(label="Hurricane Formation Verdict")
|
| 803 |
+
hurricane_plot = gr.Plot(label="Trust Modulation Plot")
|
| 804 |
+
|
| 805 |
+
hurricane_predict_btn.click(
|
| 806 |
+
fn=lambda sst, sst_unit, ohc, humid, shear, vort, trust, axis: (
|
| 807 |
+
predict_hurricane(sst, ohc, humid, shear, vort, sst_unit, trust),
|
| 808 |
+
generate_hurricane_plot(axis, trust)
|
| 809 |
+
),
|
| 810 |
+
inputs=[
|
| 811 |
+
sst_input, sst_unit, ohc_input, humidity_input,
|
| 812 |
+
shear_input, vort_input, use_trust_cyclone,
|
| 813 |
+
hurricane_sweep_axis
|
| 814 |
+
],
|
| 815 |
+
outputs=[hurricane_output, hurricane_plot]
|
| 816 |
+
)
|
| 817 |
+
|
| 818 |
+
|
| 819 |
app = FastAPI()
|
| 820 |
|
| 821 |
app.add_middleware(
|