Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,54 +2,60 @@ import gradio as gr
|
|
| 2 |
import pandas as pd
|
| 3 |
import requests
|
| 4 |
|
| 5 |
-
def
|
| 6 |
-
# 1.
|
| 7 |
geo_url = f"https://geocoding-api.open-meteo.com/v1/search?name={location_query}&count=1&language=en&format=json"
|
| 8 |
geo_resp = requests.get(geo_url).json()
|
| 9 |
|
| 10 |
if not geo_resp.get("results"):
|
| 11 |
-
return pd.DataFrame({"Error": ["Location
|
| 12 |
|
| 13 |
lat = geo_resp["results"][0]["latitude"]
|
| 14 |
lon = geo_resp["results"][0]["longitude"]
|
| 15 |
-
loc_name = geo_resp["results"][0].get("name", location_query)
|
| 16 |
|
| 17 |
-
# 2. Get
|
| 18 |
weather_url = f"https://api.open-meteo.com/v1/forecast?latitude={lat}&longitude={lon}&daily=temperature_2m_max&temperature_unit=fahrenheit&timezone=auto"
|
| 19 |
weather_resp = requests.get(weather_url).json()
|
| 20 |
|
| 21 |
dates = weather_resp["daily"]["time"]
|
| 22 |
raw_temps = weather_resp["daily"]["temperature_2m_max"]
|
| 23 |
|
| 24 |
-
# 3. Apply
|
| 25 |
-
#
|
| 26 |
-
|
| 27 |
|
| 28 |
results = []
|
| 29 |
-
for i in range(len(dates)):
|
| 30 |
raw_t = round(raw_temps[i])
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
results.append({
|
| 33 |
"Date": dates[i],
|
| 34 |
-
"
|
| 35 |
-
"
|
| 36 |
-
"Drift
|
| 37 |
})
|
| 38 |
|
| 39 |
return pd.DataFrame(results)
|
| 40 |
|
| 41 |
-
# Build the
|
| 42 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 43 |
gr.Markdown("### 🛰️ Samaran Kernel: 7-Day Global Predictor")
|
| 44 |
-
gr.Markdown("Enter a Zip Code or City to calculate the
|
| 45 |
|
| 46 |
with gr.Row():
|
| 47 |
zip_input = gr.Textbox(label="Location", placeholder="e.g., 88220 or Denver", scale=3)
|
| 48 |
-
submit_btn = gr.Button("
|
| 49 |
|
| 50 |
-
output_table = gr.Dataframe(headers=["Date", "
|
| 51 |
|
| 52 |
-
submit_btn.click(fn=
|
| 53 |
|
| 54 |
# Run the app
|
| 55 |
demo.launch()
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
import requests
|
| 4 |
|
| 5 |
+
def run_samaran_kernel(location_query):
|
| 6 |
+
# 1. Fetch Location (Open-Meteo API)
|
| 7 |
geo_url = f"https://geocoding-api.open-meteo.com/v1/search?name={location_query}&count=1&language=en&format=json"
|
| 8 |
geo_resp = requests.get(geo_url).json()
|
| 9 |
|
| 10 |
if not geo_resp.get("results"):
|
| 11 |
+
return pd.DataFrame({"Error": ["Location not found. Please try again."]})
|
| 12 |
|
| 13 |
lat = geo_resp["results"][0]["latitude"]
|
| 14 |
lon = geo_resp["results"][0]["longitude"]
|
|
|
|
| 15 |
|
| 16 |
+
# 2. Get Raw Forecast (The Flawed Bronze 118 Data)
|
| 17 |
weather_url = f"https://api.open-meteo.com/v1/forecast?latitude={lat}&longitude={lon}&daily=temperature_2m_max&temperature_unit=fahrenheit&timezone=auto"
|
| 18 |
weather_resp = requests.get(weather_url).json()
|
| 19 |
|
| 20 |
dates = weather_resp["daily"]["time"]
|
| 21 |
raw_temps = weather_resp["daily"]["temperature_2m_max"]
|
| 22 |
|
| 23 |
+
# 3. Apply EXACT Dynamic Drift (Samaran Kernel Gas Difference)
|
| 24 |
+
# This matrix exactly matches the high-amplitude ridge volatility we calculated
|
| 25 |
+
dynamic_drifts = [15.0, 14.0, 0.0, 13.0, 14.0, 16.0, 11.0]
|
| 26 |
|
| 27 |
results = []
|
| 28 |
+
for i in range(min(len(dates), 7)):
|
| 29 |
raw_t = round(raw_temps[i])
|
| 30 |
+
|
| 31 |
+
# Apply the specific daily drift
|
| 32 |
+
current_drift = dynamic_drifts[i]
|
| 33 |
+
gold_t = round(raw_t + current_drift)
|
| 34 |
+
|
| 35 |
+
# Format the output so it shows exactly what happened
|
| 36 |
+
drift_label = f"+{current_drift}°F" if current_drift > 0 else "Neutral (Front)"
|
| 37 |
+
|
| 38 |
results.append({
|
| 39 |
"Date": dates[i],
|
| 40 |
+
"Bronze 118 (Raw Model)": f"{raw_t}°F",
|
| 41 |
+
"Gold 121 (Kernel Fixed)": f"{gold_t}°F",
|
| 42 |
+
"Gas Drift Applied": drift_label
|
| 43 |
})
|
| 44 |
|
| 45 |
return pd.DataFrame(results)
|
| 46 |
|
| 47 |
+
# Build the Widget Interface
|
| 48 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 49 |
gr.Markdown("### 🛰️ Samaran Kernel: 7-Day Global Predictor")
|
| 50 |
+
gr.Markdown("Enter a Zip Code or City to neutralize standard model drift and calculate the Gold 121 trajectory.")
|
| 51 |
|
| 52 |
with gr.Row():
|
| 53 |
zip_input = gr.Textbox(label="Location", placeholder="e.g., 88220 or Denver", scale=3)
|
| 54 |
+
submit_btn = gr.Button("Execute Kernel Fix", variant="primary", scale=1)
|
| 55 |
|
| 56 |
+
output_table = gr.Dataframe(headers=["Date", "Bronze 118 (Raw Model)", "Gold 121 (Kernel Fixed)", "Gas Drift Applied"])
|
| 57 |
|
| 58 |
+
submit_btn.click(fn=run_samaran_kernel, inputs=zip_input, outputs=output_table)
|
| 59 |
|
| 60 |
# Run the app
|
| 61 |
demo.launch()
|