KAPtechies commited on
Commit
86f4fb8
·
verified ·
1 Parent(s): b8115d1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -5
app.py CHANGED
@@ -2,6 +2,38 @@ import requests
2
  import gradio as gr
3
  import pandas as pd
4
  import os
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
  var1 = os.getenv("variable_1")
7
  var2 = os.getenv("variable_2")
@@ -12,9 +44,7 @@ def get_weather(city):
12
 
13
  if response.get("cod") != "200":
14
  return "<span style='color:red; font-weight:bold;'>❌ Invalid city name! Please enter a correct city.</span>"
15
-
16
-
17
-
18
  weather_info = {}
19
 
20
  # Organizing data by date
@@ -47,7 +77,6 @@ def get_weather(city):
47
  {table_html}
48
  </div>
49
  """
50
-
51
  return markdown_output
52
 
53
  # **Adding Background Image and Box Styling**
@@ -101,4 +130,4 @@ iface = gr.Interface(
101
  )
102
 
103
  if __name__ == "__main__":
104
- iface.launch()
 
2
  import gradio as gr
3
  import pandas as pd
4
  import os
5
+ from sklearn.ensemble import RandomForestRegressor
6
+ from sklearn.model_selection import train_test_split
7
+ from sklearn.preprocessing import LabelEncoder
8
+ import numpy as np
9
+ from datetime import datetime, timedelta
10
+
11
+ # Load dataset
12
+ file_path = "weather_data_2015.csv"
13
+ df = pd.read_csv(file_path)
14
+
15
+ # Convert Date to Datetime
16
+ df['Date'] = pd.to_datetime(df['Date'])
17
+
18
+ # Encode country names as numbers
19
+ le = LabelEncoder()
20
+ df['Country'] = le.fit_transform(df['Country'])
21
+
22
+ # Extract useful features
23
+ df['Hour'] = df['Date'].dt.hour
24
+ df['Day'] = df['Date'].dt.day
25
+ df['Month'] = df['Date'].dt.month
26
+
27
+ # Features and Targets
28
+ X = df[['Hour', 'Day', 'Month', 'Country']] # Country is now encoded
29
+ y = df[['Temperature', 'Humidity', 'Pressure', 'Rain', 'Cloud']]
30
+
31
+ # Split data
32
+ X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
33
+
34
+ # Train Model
35
+ model = RandomForestRegressor(n_estimators=100, random_state=42)
36
+ model.fit(X_train, y_train)
37
 
38
  var1 = os.getenv("variable_1")
39
  var2 = os.getenv("variable_2")
 
44
 
45
  if response.get("cod") != "200":
46
  return "<span style='color:red; font-weight:bold;'>❌ Invalid city name! Please enter a correct city.</span>"
47
+
 
 
48
  weather_info = {}
49
 
50
  # Organizing data by date
 
77
  {table_html}
78
  </div>
79
  """
 
80
  return markdown_output
81
 
82
  # **Adding Background Image and Box Styling**
 
130
  )
131
 
132
  if __name__ == "__main__":
133
+ iface.launch()