Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,6 @@ import numpy as np
|
|
| 3 |
import pandas as pd
|
| 4 |
import folium
|
| 5 |
import gradio as gr
|
| 6 |
-
from folium import Map
|
| 7 |
|
| 8 |
# Function to load the saved model
|
| 9 |
def load_model():
|
|
@@ -47,7 +46,7 @@ def predict_next_6_rows(lat_present, lon_present, dist2land_present, storm_speed
|
|
| 47 |
# Display the DataFrame
|
| 48 |
return df_predictions
|
| 49 |
|
| 50 |
-
# Function to plot predictions on a folium map and
|
| 51 |
def plot_predictions_on_map(df_predictions):
|
| 52 |
# Extract LAT and LON from the predictions
|
| 53 |
latitudes = df_predictions['LAT'].tolist()
|
|
@@ -66,8 +65,11 @@ def plot_predictions_on_map(df_predictions):
|
|
| 66 |
# Add a polyline to connect the points
|
| 67 |
folium.PolyLine(locations, color='blue', weight=2.5, opacity=0.7).add_to(m)
|
| 68 |
|
| 69 |
-
#
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
# Function for the Gradio interface
|
| 73 |
def gradio_interface(lat_present, lon_present, dist2land_present, storm_speed_present,
|
|
@@ -79,11 +81,11 @@ def gradio_interface(lat_present, lon_present, dist2land_present, storm_speed_pr
|
|
| 79 |
year_present, month_present, day_present, hour_present,
|
| 80 |
lat_prev, lon_prev, dist2land_prev, storm_speed_prev)
|
| 81 |
|
| 82 |
-
# Generate the map
|
| 83 |
-
|
| 84 |
|
| 85 |
-
# Return the DataFrame as HTML and the map
|
| 86 |
-
return df_predictions.to_html(),
|
| 87 |
|
| 88 |
# Gradio Interface Setup
|
| 89 |
inputs = [
|
|
@@ -100,5 +102,3 @@ outputs = [gr.HTML(label="Predicted DataFrame"), gr.HTML(label="Generated Map")]
|
|
| 100 |
# Launch the Gradio App
|
| 101 |
gr.Interface(fn=gradio_interface, inputs=inputs, outputs=outputs, title="Cyclone Path Prediction",
|
| 102 |
description="Input current and previous cyclone data to predict the next 6 rows and visualize the path on a map").launch()
|
| 103 |
-
|
| 104 |
-
|
|
|
|
| 3 |
import pandas as pd
|
| 4 |
import folium
|
| 5 |
import gradio as gr
|
|
|
|
| 6 |
|
| 7 |
# Function to load the saved model
|
| 8 |
def load_model():
|
|
|
|
| 46 |
# Display the DataFrame
|
| 47 |
return df_predictions
|
| 48 |
|
| 49 |
+
# Function to plot predictions on a folium map and save it to an HTML file
|
| 50 |
def plot_predictions_on_map(df_predictions):
|
| 51 |
# Extract LAT and LON from the predictions
|
| 52 |
latitudes = df_predictions['LAT'].tolist()
|
|
|
|
| 65 |
# Add a polyline to connect the points
|
| 66 |
folium.PolyLine(locations, color='blue', weight=2.5, opacity=0.7).add_to(m)
|
| 67 |
|
| 68 |
+
# Save the map to an HTML file
|
| 69 |
+
map_path = "map.html"
|
| 70 |
+
m.save(map_path)
|
| 71 |
+
|
| 72 |
+
return map_path
|
| 73 |
|
| 74 |
# Function for the Gradio interface
|
| 75 |
def gradio_interface(lat_present, lon_present, dist2land_present, storm_speed_present,
|
|
|
|
| 81 |
year_present, month_present, day_present, hour_present,
|
| 82 |
lat_prev, lon_prev, dist2land_prev, storm_speed_prev)
|
| 83 |
|
| 84 |
+
# Generate the map and return its file path
|
| 85 |
+
map_path = plot_predictions_on_map(df_predictions)
|
| 86 |
|
| 87 |
+
# Return the DataFrame as HTML and the path to the map embedded in an iframe
|
| 88 |
+
return df_predictions.to_html(), f'<iframe src="{map_path}" width="100%" height="500"></iframe>'
|
| 89 |
|
| 90 |
# Gradio Interface Setup
|
| 91 |
inputs = [
|
|
|
|
| 102 |
# Launch the Gradio App
|
| 103 |
gr.Interface(fn=gradio_interface, inputs=inputs, outputs=outputs, title="Cyclone Path Prediction",
|
| 104 |
description="Input current and previous cyclone data to predict the next 6 rows and visualize the path on a map").launch()
|
|
|
|
|
|