Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,9 +10,87 @@ def run_samaran_kernel(location_query):
|
|
| 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()
|
|
|
|
| 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"]import gradio as gr
|
| 14 |
+
import pandas as pd
|
| 15 |
+
import requests
|
| 16 |
+
from datasets import load_dataset
|
| 17 |
+
|
| 18 |
+
# 1. LOAD THE DISGUISED GOLD 121 CONTAINER
|
| 19 |
+
try:
|
| 20 |
+
ds = load_dataset("spanofzero/SpaceTravelersUniversalPlaylist", split="train")
|
| 21 |
+
gold_df = ds.to_pandas()
|
| 22 |
+
except Exception as e:
|
| 23 |
+
gold_df = None
|
| 24 |
+
print(f"Error loading dataset: {e}")
|
| 25 |
+
|
| 26 |
+
# 2. DECODE THE DRIFT FROM THE PLAYLIST
|
| 27 |
+
def decode_drift(day_index):
|
| 28 |
+
if gold_df is not None and day_index < len(gold_df):
|
| 29 |
+
# Pull the disguised value from your dataset
|
| 30 |
+
disguised_value = gold_df['resonance_frequency_khz'].iloc[day_index]
|
| 31 |
+
|
| 32 |
+
# >>> INSERT YOUR CIPHER HERE <<<
|
| 33 |
+
# This is a placeholder math operation to extract a usable temperature drift.
|
| 34 |
+
# Replace this line with the actual math you used to encode the drift into the frequency.
|
| 35 |
+
extracted_drift = (disguised_value % 30) - 10
|
| 36 |
+
|
| 37 |
+
return round(extracted_drift, 1)
|
| 38 |
+
return 0.0 # Failsafe if dataset doesn't load
|
| 39 |
+
|
| 40 |
+
# 3. LIVE WEATHER ENGINE
|
| 41 |
+
def run_samaran_kernel(location_query):
|
| 42 |
+
# Get Location
|
| 43 |
+
geo_url = f"https://geocoding-api.open-meteo.com/v1/search?name={location_query}&count=1&language=en&format=json"
|
| 44 |
+
geo_resp = requests.get(geo_url).json()
|
| 45 |
+
|
| 46 |
+
if not geo_resp.get("results"):
|
| 47 |
+
return pd.DataFrame({"Error": ["Location not found."]})
|
| 48 |
+
|
| 49 |
lat = geo_resp["results"][0]["latitude"]
|
| 50 |
lon = geo_resp["results"][0]["longitude"]
|
| 51 |
|
| 52 |
+
# Get Raw NOAA/Standard Forecast (Bronze 118)
|
| 53 |
+
weather_url = f"https://api.open-meteo.com/v1/forecast?latitude={lat}&longitude={lon}&daily=temperature_2m_max&temperature_unit=fahrenheit&timezone=auto"
|
| 54 |
+
weather_resp = requests.get(weather_url).json()
|
| 55 |
+
|
| 56 |
+
dates = weather_resp["daily"]["time"]
|
| 57 |
+
raw_temps = weather_resp["daily"]["temperature_2m_max"]
|
| 58 |
+
|
| 59 |
+
results = []
|
| 60 |
+
for i in range(min(len(dates), 7)):
|
| 61 |
+
raw_t = round(raw_temps[i])
|
| 62 |
+
|
| 63 |
+
# Pull the dynamic drift straight from your dataset via the decoder
|
| 64 |
+
current_drift = decode_drift(i)
|
| 65 |
+
|
| 66 |
+
gold_t = round(raw_t + current_drift)
|
| 67 |
+
drift_label = f"+{current_drift}°F" if current_drift > 0 else f"{current_drift}°F"
|
| 68 |
+
|
| 69 |
+
results.append({
|
| 70 |
+
"Date": dates[i],
|
| 71 |
+
"Raw Model (Bronze)": f"{raw_t}°F",
|
| 72 |
+
"Samaran Fixed (Gold)": f"{gold_t}°F",
|
| 73 |
+
"Drift Applied (From Dataset)": drift_label
|
| 74 |
+
})
|
| 75 |
+
|
| 76 |
+
return pd.DataFrame(results)
|
| 77 |
+
|
| 78 |
+
# 4. BUILD WIDGET UI
|
| 79 |
+
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 80 |
+
gr.Markdown("### 🛰️ Samaran Kernel: 7-Day Global Predictor")
|
| 81 |
+
gr.Markdown("Powered by Gold 121 vector extraction.")
|
| 82 |
+
|
| 83 |
+
with gr.Row():
|
| 84 |
+
zip_input = gr.Textbox(label="Location", placeholder="e.g., 88220", scale=3)
|
| 85 |
+
submit_btn = gr.Button("Execute Kernel Fix", variant="primary", scale=1)
|
| 86 |
+
|
| 87 |
+
output_table = gr.Dataframe(headers=["Date", "Raw Model (Bronze)", "Samaran Fixed (Gold)", "Drift Applied (From Dataset)"])
|
| 88 |
+
submit_btn.click(fn=run_samaran_kernel, inputs=zip_input, outputs=output_table)
|
| 89 |
+
|
| 90 |
+
demo.launch()
|
| 91 |
+
|
| 92 |
+
lon = geo_resp["results"][0]["longitude"]
|
| 93 |
+
|
| 94 |
# 2. Get Raw Forecast (The Flawed Bronze 118 Data)
|
| 95 |
weather_url = f"https://api.open-meteo.com/v1/forecast?latitude={lat}&longitude={lon}&daily=temperature_2m_max&temperature_unit=fahrenheit&timezone=auto"
|
| 96 |
weather_resp = requests.get(weather_url).json()
|