rafat0421 commited on
Commit
5aeda22
1 Parent(s): 26ba9f4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -28
app.py CHANGED
@@ -1,4 +1,3 @@
1
- import streamlit as st
2
  import gradio as gr
3
  import hopsworks
4
  import joblib
@@ -16,35 +15,33 @@ project = hopsworks.login()
16
  fs = project.get_feature_store()
17
 
18
 
19
- weather_df = pd.DataFrame()
20
- for i in range(8):
21
- weather_data = get_weather_df([get_weather_data((datetime.now() + timedelta(days=i)).strftime("%Y-%m-%d"))])
22
- weather_df = weather_df.append(weather_data)
 
23
 
24
- weather_df = weather_df.drop(columns=["precipprob", "uvindex", "date","city","conditions"]).fillna(0)
25
 
26
- mr = project.get_model_registry()
27
- model = mr.get_model("lond_gradient_boost_model", version=1)
28
- model_dir = model.download()
29
- model = joblib.load(model_dir + "/lond_model.pkl")
30
 
31
- preds = model.predict(weather_df)
 
 
 
 
 
 
 
 
 
 
 
32
 
33
- predictions = ''
34
- for k in range(7):
35
- predictions += "Predicted AQI on " + (datetime.now() + timedelta(days=k)).strftime('%Y-%m-%d') + ": " + str(int(preds[k]))+"\n"
36
-
37
-
38
- air_pollution_level = ['Good', 'Moderate', 'Unhealthy for sensitive Groups','Unhealthy' ,'Very Unhealthy', 'Hazardous']
39
- poll_level = get_aplevel(preds.T.reshape(-1, 1), air_pollution_level)
40
-
41
- next_week_datetime = [today + datetime.timedelta(days=d) for d in range(7)]
42
- next_week_str = [f"{days.strftime('%A')}, {days.strftime('%Y-%m-%d')}" for days in next_week_datetime]
43
-
44
- df = pd.DataFrame(data=[preds, poll_level], index=["AQI", "Air pollution level"], columns=next_week_str)
45
-
46
- st.write("Here they are!")
47
- st.dataframe(df.style.apply(get_color, subset=(["Air pollution level"], slice(None))))
48
 
49
- st.button("Re-run")
50
-
 
 
 
1
  import gradio as gr
2
  import hopsworks
3
  import joblib
 
15
  fs = project.get_feature_store()
16
 
17
 
18
+ def air_quality(city):
19
+ weather_df = pd.DataFrame()
20
+ for i in range(8):
21
+ weather_data = get_weather_df([get_weather_data((datetime.now() + timedelta(days=i)).strftime("%Y-%m-%d"))])
22
+ weather_df = weather_df.append(weather_data)
23
 
24
+ weather_df = weather_df.drop(columns=["precipprob", "uvindex", "date","city","conditions"]).fillna(0)
25
 
26
+ mr = project.get_model_registry()
27
+ model = mr.get_model("lond_gradient_boost_model", version=1)
28
+ model_dir = model.download()
29
+ model = joblib.load(model_dir + "/lond_model.pkl")
30
 
31
+ preds = model.predict(weather_df)
32
+
33
+ predictions = ''
34
+ for k in range(7):
35
+ predictions += "Predicted AQI on " + (datetime.now() + timedelta(days=k)).strftime('%Y-%m-%d') + ": " + str(int(preds[k]))+"\n"
36
+
37
+ print(predictions)
38
+ return predictions
39
+
40
+
41
+ demo = gr.Interface(fn=air_quality, title="Air quality predictor",
42
+ description="Input a value to get next weeks AQI prediction for London", inputs="text", outputs="text")
43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
 
45
+
46
+ if __name__ == "__main__":
47
+ demo.launch()