Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,9 @@
|
|
| 1 |
# -*- coding: utf-8 -*-
|
| 2 |
-
"""app.ipynb
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
import gradio as gr
|
| 5 |
import xarray as xr
|
|
@@ -12,6 +16,7 @@ from datetime import datetime
|
|
| 12 |
import fsspec
|
| 13 |
|
| 14 |
# Filepath for NASA POWER data
|
|
|
|
| 15 |
FILEPATH = 'https://nasa-power.s3.amazonaws.com/syn1deg/temporal/power_syn1deg_monthly_temporal_lst.zarr'
|
| 16 |
|
| 17 |
# Load dataset
|
|
@@ -67,34 +72,31 @@ def predict_forecast(lat, lon, start_date, end_date, forecast_steps):
|
|
| 67 |
except Exception as e:
|
| 68 |
return f"Error: {str(e)}"
|
| 69 |
|
| 70 |
-
# Gradio
|
| 71 |
-
def gradio_interface(
|
| 72 |
-
if location is None or len(location) != 2:
|
| 73 |
-
return "Please select a location on the map.", None, None
|
| 74 |
-
lat, lon = location
|
| 75 |
result = predict_forecast(lat, lon, start_date, end_date, forecast_steps)
|
| 76 |
if isinstance(result, dict): # If successful
|
| 77 |
-
return
|
| 78 |
else: # If error
|
| 79 |
return result, None, None
|
| 80 |
|
| 81 |
-
# Gradio UI
|
| 82 |
interface = gr.Interface(
|
| 83 |
fn=gradio_interface,
|
| 84 |
inputs=[
|
| 85 |
-
gr.
|
| 86 |
-
gr.
|
| 87 |
-
gr.Textbox(label="
|
| 88 |
-
gr.
|
|
|
|
| 89 |
],
|
| 90 |
outputs=[
|
| 91 |
gr.Textbox(label="RMSE"),
|
| 92 |
gr.Textbox(label="Forecast Values"),
|
| 93 |
gr.Image(label="Forecast Plot")
|
| 94 |
],
|
| 95 |
-
title="
|
| 96 |
-
description="
|
| 97 |
)
|
| 98 |
|
| 99 |
# Launch the app
|
| 100 |
-
interface.launch()
|
|
|
|
| 1 |
# -*- coding: utf-8 -*-
|
| 2 |
+
"""app.ipynb
|
| 3 |
+
Automatically generated by Colab.
|
| 4 |
+
Original file is located at
|
| 5 |
+
https://colab.research.google.com/drive/1I5SzMTkFWVzSyzaZNkQcYqUi7F9Nzxpx
|
| 6 |
+
"""
|
| 7 |
|
| 8 |
import gradio as gr
|
| 9 |
import xarray as xr
|
|
|
|
| 16 |
import fsspec
|
| 17 |
|
| 18 |
# Filepath for NASA POWER data
|
| 19 |
+
# FILEPATH = 'https://power-analysis-ready-datastore.s3.amazonaws.com/power_901_monthly_radiation_utc.zarr'
|
| 20 |
FILEPATH = 'https://nasa-power.s3.amazonaws.com/syn1deg/temporal/power_syn1deg_monthly_temporal_lst.zarr'
|
| 21 |
|
| 22 |
# Load dataset
|
|
|
|
| 72 |
except Exception as e:
|
| 73 |
return f"Error: {str(e)}"
|
| 74 |
|
| 75 |
+
# Gradio app
|
| 76 |
+
def gradio_interface(lat, lon, start_date, end_date, forecast_steps):
|
|
|
|
|
|
|
|
|
|
| 77 |
result = predict_forecast(lat, lon, start_date, end_date, forecast_steps)
|
| 78 |
if isinstance(result, dict): # If successful
|
| 79 |
+
return result["RMSE"], result["Forecast"], result["Plot"]
|
| 80 |
else: # If error
|
| 81 |
return result, None, None
|
| 82 |
|
|
|
|
| 83 |
interface = gr.Interface(
|
| 84 |
fn=gradio_interface,
|
| 85 |
inputs=[
|
| 86 |
+
gr.Number(label="Latitude"),
|
| 87 |
+
gr.Number(label="Longitude"),
|
| 88 |
+
gr.Textbox(label="Start Date (YYYY-MM-DD)", placeholder="2019-01-01"),
|
| 89 |
+
gr.Textbox(label="End Date (YYYY-MM-DD)", placeholder="2024-12-31"),
|
| 90 |
+
gr.Number(label="Forecast Steps (e.g., 12 for 1 year)")
|
| 91 |
],
|
| 92 |
outputs=[
|
| 93 |
gr.Textbox(label="RMSE"),
|
| 94 |
gr.Textbox(label="Forecast Values"),
|
| 95 |
gr.Image(label="Forecast Plot")
|
| 96 |
],
|
| 97 |
+
title="Solar Radiation Forecast with SARIMA",
|
| 98 |
+
description="Enter location and time range to forecast solar radiation using SARIMA."
|
| 99 |
)
|
| 100 |
|
| 101 |
# Launch the app
|
| 102 |
+
interface.launch()
|