Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,35 @@ import gradio as gr
|
|
| 2 |
import joblib
|
| 3 |
import pandas as pd
|
| 4 |
import numpy as np
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
# -------------------------------------------------
|
| 7 |
# Load trained artifact (NO dataset, NO training)
|
| 8 |
# -------------------------------------------------
|
|
|
|
| 2 |
import joblib
|
| 3 |
import pandas as pd
|
| 4 |
import numpy as np
|
| 5 |
+
import requests
|
| 6 |
+
|
| 7 |
+
API_KEY = "YOUR_API_KEY"
|
| 8 |
+
CITY = "Hyderabad" # or your service city
|
| 9 |
+
|
| 10 |
+
def get_weather_features():
|
| 11 |
+
try:
|
| 12 |
+
url = "https://api.openweathermap.org/data/2.5/weather"
|
| 13 |
+
params = {"q": CITY, "appid": API_KEY, "units": "metric"}
|
| 14 |
+
data = requests.get(url, params=params, timeout=5).json()
|
| 15 |
+
|
| 16 |
+
condition = data["weather"][0]["main"]
|
| 17 |
+
temp = data["main"]["temp"]
|
| 18 |
+
|
| 19 |
+
if condition == "Clear":
|
| 20 |
+
weather_factor = 1.0
|
| 21 |
+
elif condition == "Clouds":
|
| 22 |
+
weather_factor = 1.05
|
| 23 |
+
elif condition == "Rain":
|
| 24 |
+
weather_factor = 1.20
|
| 25 |
+
elif condition == "Thunderstorm":
|
| 26 |
+
weather_factor = 1.30
|
| 27 |
+
else:
|
| 28 |
+
weather_factor = 1.0
|
| 29 |
+
|
| 30 |
+
return weather_factor, temp
|
| 31 |
+
|
| 32 |
+
except:
|
| 33 |
+
return 1.0, 30
|
| 34 |
# -------------------------------------------------
|
| 35 |
# Load trained artifact (NO dataset, NO training)
|
| 36 |
# -------------------------------------------------
|