Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
CHANGED
|
@@ -1,40 +1,55 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
| 3 |
-
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
df = ds['train'].to_pandas()
|
| 10 |
-
return df.head(10) # Shows the first 10 rows
|
| 11 |
-
except Exception as e:
|
| 12 |
-
return pd.DataFrame({"Error": [f"Could not load dataset: {e}"]})
|
| 13 |
-
|
| 14 |
-
# 2. The Samaran Kernel Logic (Neutralizing the Drift)
|
| 15 |
-
def run_kernel(bronze_temp, drift):
|
| 16 |
-
return bronze_temp + drift
|
| 17 |
-
|
| 18 |
-
# 3. Build the Widget Interface
|
| 19 |
-
with gr.Blocks(theme=gr.themes.Monochrome()) as demo:
|
| 20 |
-
gr.Markdown("# 🛰️ Samaran Kernel: Global Weather Stabilizer")
|
| 21 |
-
gr.Markdown("### 100% ROC Predictable Trajectory Widget")
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
-
|
| 38 |
|
| 39 |
# Run the app
|
| 40 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
| 3 |
+
import requests
|
| 4 |
|
| 5 |
+
def get_7_day_forecast(location_query):
|
| 6 |
+
# 1. Find the location (Geocoding via free 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 or Zip Code not found. Try again."]})
|
| 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 the raw 7-day weather forecast (The Bronze 118 data)
|
| 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 the Samaran Kernel Drift Correction
|
| 25 |
+
# (Using a baseline +12 degree fix for the current gas difference anomaly)
|
| 26 |
+
drift = 12.0
|
| 27 |
+
|
| 28 |
+
results = []
|
| 29 |
+
for i in range(len(dates)):
|
| 30 |
+
raw_t = round(raw_temps[i])
|
| 31 |
+
fixed_t = round(raw_t + drift)
|
| 32 |
+
results.append({
|
| 33 |
+
"Date": dates[i],
|
| 34 |
+
"Raw Model (Bronze)": f"{raw_t}°F",
|
| 35 |
+
"Samaran Fixed (Gold)": f"{fixed_t}°F",
|
| 36 |
+
"Drift Corrected": f"+{drift}°F"
|
| 37 |
+
})
|
| 38 |
+
|
| 39 |
+
return pd.DataFrame(results)
|
| 40 |
+
|
| 41 |
+
# Build the cleaner Widget Interface
|
| 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 100% ROC trajectory.")
|
| 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("Generate Stabilized Forecast", variant="primary", scale=1)
|
| 49 |
+
|
| 50 |
+
output_table = gr.Dataframe(headers=["Date", "Raw Model (Bronze)", "Samaran Fixed (Gold)", "Drift Corrected"])
|
| 51 |
|
| 52 |
+
submit_btn.click(fn=get_7_day_forecast, inputs=zip_input, outputs=output_table)
|
| 53 |
|
| 54 |
# Run the app
|
| 55 |
demo.launch()
|