Update app.py
Browse files
app.py
CHANGED
@@ -115,30 +115,37 @@ def preprocess_csv_for_prediction(csv_file):
|
|
115 |
try:
|
116 |
# Load the dataset
|
117 |
data = pd.read_csv(csv_file.name)
|
118 |
-
|
119 |
# Validate column names
|
120 |
expected_columns = ['Month', 'Hour', 'Irradiance(W/m^2)', 'Latitude', 'Longitude',
|
121 |
'Panel_Capacity(W)', 'Panel_Efficiency', 'Wind_Speed(km/h)',
|
122 |
'Cloud_Cover(%)', 'temperature (°f)']
|
123 |
if not all(col in data.columns for col in expected_columns):
|
124 |
return f"Error: Missing expected columns. Required: {expected_columns}"
|
125 |
-
|
126 |
-
#
|
127 |
-
|
128 |
-
|
129 |
-
#
|
130 |
-
|
131 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
# Reshape the data to match the model's input shape
|
133 |
sequence = last_row.values.astype(np.float32)
|
134 |
sequence = sequence.reshape((1, 1, 43)) # (batch_size, time_step, features)
|
135 |
-
|
136 |
return sequence
|
137 |
except Exception as e:
|
138 |
return f"Error in preprocessing CSV: {str(e)}"
|
139 |
|
140 |
|
141 |
|
|
|
142 |
# Function to process image and forecast energy using CSV file
|
143 |
# Function to process image and forecast energy using CSV file
|
144 |
def process_image_and_forecast(image, min_area, pixel_area, clip_limit, tile_size, panel_type,
|
|
|
115 |
try:
|
116 |
# Load the dataset
|
117 |
data = pd.read_csv(csv_file.name)
|
118 |
+
|
119 |
# Validate column names
|
120 |
expected_columns = ['Month', 'Hour', 'Irradiance(W/m^2)', 'Latitude', 'Longitude',
|
121 |
'Panel_Capacity(W)', 'Panel_Efficiency', 'Wind_Speed(km/h)',
|
122 |
'Cloud_Cover(%)', 'temperature (°f)']
|
123 |
if not all(col in data.columns for col in expected_columns):
|
124 |
return f"Error: Missing expected columns. Required: {expected_columns}"
|
125 |
+
|
126 |
+
# Ensure columns with string values like 'Month' are removed or processed
|
127 |
+
data = data[expected_columns]
|
128 |
+
|
129 |
+
# Convert all non-numeric columns to numeric (handling errors where conversion is not possible)
|
130 |
+
data = data.apply(pd.to_numeric, errors='coerce')
|
131 |
+
|
132 |
+
# Handle any missing values (NaNs)
|
133 |
+
data.fillna(0, inplace=True)
|
134 |
+
|
135 |
+
# Select the relevant last row for prediction
|
136 |
+
last_row = data.tail(1)
|
137 |
+
|
138 |
# Reshape the data to match the model's input shape
|
139 |
sequence = last_row.values.astype(np.float32)
|
140 |
sequence = sequence.reshape((1, 1, 43)) # (batch_size, time_step, features)
|
141 |
+
|
142 |
return sequence
|
143 |
except Exception as e:
|
144 |
return f"Error in preprocessing CSV: {str(e)}"
|
145 |
|
146 |
|
147 |
|
148 |
+
|
149 |
# Function to process image and forecast energy using CSV file
|
150 |
# Function to process image and forecast energy using CSV file
|
151 |
def process_image_and_forecast(image, min_area, pixel_area, clip_limit, tile_size, panel_type,
|