Update app.py
Browse files
app.py
CHANGED
|
@@ -13,6 +13,17 @@ from torch.utils.data import Dataset, DataLoader
|
|
| 13 |
from torch.optim.lr_scheduler import ReduceLROnPlateau
|
| 14 |
from sklearn.model_selection import train_test_split
|
| 15 |
import glob
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
class ClimateNet(nn.Module):
|
| 18 |
def __init__(self, input_size=(256, 256), output_size=(64, 64)):
|
|
@@ -307,7 +318,7 @@ class ClimatePredictor:
|
|
| 307 |
raise e
|
| 308 |
|
| 309 |
def load_examples_from_directory(base_dir):
|
| 310 |
-
"""ํด๋์์ ์์ ๋ฐ์ดํฐ ๋ก๋"""
|
| 311 |
examples = []
|
| 312 |
sample_dirs = sorted(glob.glob(os.path.join(base_dir, "sample_*")))
|
| 313 |
|
|
@@ -319,7 +330,13 @@ def load_examples_from_directory(base_dir):
|
|
| 319 |
elevation_path = os.path.join(sample_dir, "terrain", "elevation_data.npy")
|
| 320 |
weather_path = os.path.join(sample_dir, "weather", "weather_data.csv")
|
| 321 |
|
| 322 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 323 |
wind_speed = weather_data['wind_speed'].mean()
|
| 324 |
wind_direction = weather_data['wind_direction'].mean()
|
| 325 |
temperature = weather_data['temperature'].mean()
|
|
@@ -335,12 +352,15 @@ def load_examples_from_directory(base_dir):
|
|
| 335 |
float(temperature),
|
| 336 |
float(humidity)
|
| 337 |
])
|
|
|
|
| 338 |
except Exception as e:
|
| 339 |
print(f"Error loading example from {sample_dir}: {str(e)}")
|
| 340 |
continue
|
| 341 |
|
|
|
|
| 342 |
return examples
|
| 343 |
|
|
|
|
| 344 |
def create_gradio_interface():
|
| 345 |
predictor = ClimatePredictor('best_model.pth')
|
| 346 |
|
|
|
|
| 13 |
from torch.optim.lr_scheduler import ReduceLROnPlateau
|
| 14 |
from sklearn.model_selection import train_test_split
|
| 15 |
import glob
|
| 16 |
+
import sys
|
| 17 |
+
import csv
|
| 18 |
+
|
| 19 |
+
maxInt = sys.maxsize
|
| 20 |
+
|
| 21 |
+
while True:
|
| 22 |
+
try:
|
| 23 |
+
csv.field_size_limit(maxInt)
|
| 24 |
+
break
|
| 25 |
+
except OverflowError:
|
| 26 |
+
maxInt = int(maxInt/10)
|
| 27 |
|
| 28 |
class ClimateNet(nn.Module):
|
| 29 |
def __init__(self, input_size=(256, 256), output_size=(64, 64)):
|
|
|
|
| 318 |
raise e
|
| 319 |
|
| 320 |
def load_examples_from_directory(base_dir):
|
| 321 |
+
"""ํด๋์์ ์์ ๋ฐ์ดํฐ ๋ก๋ - CSV ์ฒ๋ฆฌ ๊ฐ์ """
|
| 322 |
examples = []
|
| 323 |
sample_dirs = sorted(glob.glob(os.path.join(base_dir, "sample_*")))
|
| 324 |
|
|
|
|
| 330 |
elevation_path = os.path.join(sample_dir, "terrain", "elevation_data.npy")
|
| 331 |
weather_path = os.path.join(sample_dir, "weather", "weather_data.csv")
|
| 332 |
|
| 333 |
+
# CSV ํ์ผ ์ฝ๊ธฐ ๊ฐ์
|
| 334 |
+
try:
|
| 335 |
+
weather_data = pd.read_csv(weather_path, engine='python')
|
| 336 |
+
except Exception as e:
|
| 337 |
+
print(f"Error reading CSV file {weather_path}: {str(e)}")
|
| 338 |
+
continue
|
| 339 |
+
|
| 340 |
wind_speed = weather_data['wind_speed'].mean()
|
| 341 |
wind_direction = weather_data['wind_direction'].mean()
|
| 342 |
temperature = weather_data['temperature'].mean()
|
|
|
|
| 352 |
float(temperature),
|
| 353 |
float(humidity)
|
| 354 |
])
|
| 355 |
+
print(f"Successfully loaded example from {sample_dir}")
|
| 356 |
except Exception as e:
|
| 357 |
print(f"Error loading example from {sample_dir}: {str(e)}")
|
| 358 |
continue
|
| 359 |
|
| 360 |
+
print(f"Total examples loaded: {len(examples)}")
|
| 361 |
return examples
|
| 362 |
|
| 363 |
+
|
| 364 |
def create_gradio_interface():
|
| 365 |
predictor = ClimatePredictor('best_model.pth')
|
| 366 |
|