Mushfi's picture
Update app.py
d736ecf
import gradio as gr
#import tensorflow as tf
import os
import numpy as np
import pandas as pd
df = pd.read_csv('graph.csv')
start_datetime = pd.to_datetime('2011-01-01 00:00:00')
df['datetime'] = start_datetime + pd.to_timedelta(df['timestep'], unit='h')
def k():
return gr.update(value=None)
def predict_input_image(file):
return '0.1854984', '8.68441'
with gr.Blocks(title="Forecasting Geomagnetic Storms", css="") as demo:
with gr.Row():
textmd = gr.Markdown('''
# Forecasting Geomagnetic Storms
The data used to build the deep learning model can be found [here](https://www.ngdc.noaa.gov/geomag/data/geomag/magnet/?fbclid=IwAR1kRkud565-Q61SiMTiB9dt2_vatxrLbNnP2oHK03JTv9HHkiGHsrcfZO0)
And the source code of our model is uploaded to Github: [NSAC2023-Dst-prediction](https://github.com/Abrar2652/NSAC2023-Dst-prediction/tree/main)
DST (Disturbance Storm Time) index is a measure of the strength of geomagnetic storms
`predicted_t0` is the predicted DST value (in nT) at the current hour
`predicted_t1` is the predicted DST value (in nT) at the next hour
Classification of DST values:
| Quiet-Minor | Moderate storm | Intense Storm | Superintense storm |
| - | - | - | - |
| >-50 | -50 to -100 | <-100 | <-250 |
''')
with gr.Row():
line = gr.LinePlot(
df,
x="datetime",
y="DST",
x_title="Datetime",
y_title="DST (nT)",
color="name",
color_legend_position="bottom",
title="Graph of Predicted DST values and Ground Truth",
tooltip=["datetime", "DST", "name"],
height=600,
width=1000,
interactive=True,
)
with gr.Row():
with gr.Column(scale=1, min_width=500):
textmd1 = gr.Markdown('''
# Realtime Forecast
## Inputs
Solar wind data should be composed of solar-wind readings from the satellites, in the form of a csv file with the following columns:
bx_gse, by_gse, bz_gse, theta_gse, phi_gse, bx_gsm, by_gsm, bz_gsm, theta_gsm, phi_gsm, bt, density, speed, temperature, source
''')
file1 = gr.File(label="Solar Wind Data (7 days)")
textmd2 = gr.Markdown('''
The satellite positions data should be composed of the daily positions of the DSCOVR and ACE Spacecrafts in Geocentric Solar Ecliptic (GSE) Coordinates for projections in the XY, XZ, and YZ planes. The csv file should have the following columns:
gse_x, gse_y, gse_z
''')
file2 = gr.File(label="Satellite Positions Data (7 days)")
number = gr.inputs.Number(label="Latest Subspot Number")
with gr.Row():
clear_btn = gr.Button("Clear")
submit_btn = gr.Button("Submit", elem_id="warning", variant='primary')
#label = gr.outputs.Label(num_top_classes=4)
#label = gr.HTML(value="<div style='height:300px; border-width: 1px; border-color: #000000; border-radius: 5px;'></div>")
with gr.Column(scale=1, min_width=200):
textmd = gr.Markdown('''
## Outputs
Predicted value of the Disturbance Storm-Time Index (Dst) at time t hour and t+1 hour
''')
label1 = gr.Textbox(label="Dst value (t)")
label2 = gr.Textbox(label="Dst value (t+1)")
clear_btn.click(k, inputs=[], outputs=file1)
submit_btn.click(predict_input_image, inputs=file1, outputs=[label1, label2])
demo.launch(debug='False', share=False)