Robzy commited on
Commit
114a7d7
1 Parent(s): 46779f8

:testing streamlit now

Browse files
.gitignore CHANGED
@@ -1,4 +1,5 @@
1
  .venv
 
2
  .env
3
  .cache.sqlite
4
- __pycache__/
 
1
  .venv
2
+ .venv_old
3
  .env
4
  .cache.sqlite
5
+ __pycache__/
app.py CHANGED
@@ -1,34 +1,37 @@
1
- import gradio as gr
2
  import pandas as pd
3
  import numpy as np
4
- import random
5
- import os
6
- import hopsworks
7
- # from gradio_datetimerange import DateTimeRange
8
 
9
- from datetime import datetime, timedelta
10
- now = datetime.now()
 
 
 
 
 
 
 
 
 
 
 
11
 
12
- api_key = os.getenv('HOPSWORKS_API_KEY')
13
- project_name = os.getenv('HOPSWORKS_PROJECT')
14
 
15
- project = hopsworks.login(project=project_name, api_key_value=api_key)
16
- fs = project.get_feature_store()
 
 
17
 
18
- air_quality_fg = fs.get_feature_group(
19
- name='air_quality',
20
- version=1,
21
- )
22
- air_quality_df = air_quality_fg.read()
23
- air_quality_df
24
 
25
- print(air_quality_df.info())
26
- print(air_quality_df)
27
 
28
- with gr.Blocks() as demo:
29
- gr.Markdown("Helsingborg Air Quality Forecast")
30
- # daterange = DateTimeRange(["now - 24h", "now"])
31
- plot = gr.LinePlot(air_quality_df, x="date", y="pm25")
32
- # daterange.bind([plot])
 
 
33
 
34
- demo.launch()
 
1
+ import streamlit as st
2
  import pandas as pd
3
  import numpy as np
 
 
 
 
4
 
5
+ st.title('Lahore Air Quality!')
6
+ st.subheader('Particle matter, diameter < 2.5 micrometers (PM2.5)')
7
+
8
+ ### Load data
9
+
10
+ import datetime
11
+ import pandas as pd
12
+ import hopsworks
13
+ import datetime
14
+ from functions import util
15
+ import os
16
+ import pandas as pd
17
+ import modal
18
 
19
+ app = modal.App('scheduler')
20
+ volume = modal.Volume.from_name("my-volume")
21
 
22
+ @app.function(schedule=modal.Period(seconds=10))
23
+ def update():
24
+ print('Updating...')
25
+
26
 
 
 
 
 
 
 
27
 
 
 
28
 
29
+ if __name__ == "__main__":
30
+ if "df" not in st.session_state:
31
+ st.session_state.df = pd.DataFrame(np.random.randn(20, 2), columns=["x", "y"])
32
+ else:
33
+ st.session_state.df = pd.DataFrame(
34
+ np.random.randn(20, 3),
35
+ columns=['a', 'b', 'c'])
36
 
37
+ st.line_chart(st.session_state.df)
app3.py ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ from random import randint, random
3
+ import gradio as gr
4
+
5
+
6
+ temp_sensor_data = pd.DataFrame(
7
+ {
8
+ "time": pd.date_range("2021-01-01", end="2021-01-05", periods=200),
9
+ "temperature": [randint(50 + 10 * (i % 2), 65 + 15 * (i % 2)) for i in range(200)],
10
+ "humidity": [randint(50 + 10 * (i % 2), 65 + 15 * (i % 2)) for i in range(200)],
11
+ "location": ["indoor", "outdoor"] * 100,
12
+ }
13
+ )
14
+
15
+ food_rating_data = pd.DataFrame(
16
+ {
17
+ "cuisine": [["Italian", "Mexican", "Chinese"][i % 3] for i in range(100)],
18
+ "rating": [random() * 4 + 0.5 * (i % 3) for i in range(100)],
19
+ "price": [randint(10, 50) + 4 * (i % 3) for i in range(100)],
20
+ "wait": [random() for i in range(100)],
21
+ }
22
+ )
23
+
24
+ with gr.Blocks() as line_plots:
25
+ with gr.Row():
26
+ start = gr.DateTime("2021-01-01 00:00:00", label="Start")
27
+ end = gr.DateTime("2021-01-05 00:00:00", label="End")
28
+ apply_btn = gr.Button("Apply", scale=0)
29
+ with gr.Row():
30
+ group_by = gr.Radio(["None", "30m", "1h", "4h", "1d"], value="None", label="Group by")
31
+ aggregate = gr.Radio(["sum", "mean", "median", "min", "max"], value="sum", label="Aggregation")
32
+
33
+ temp_by_time = gr.LinePlot(
34
+ temp_sensor_data,
35
+ x="time",
36
+ y="temperature",
37
+ )
38
+ temp_by_time_location = gr.LinePlot(
39
+ temp_sensor_data,
40
+ x="time",
41
+ y="temperature",
42
+ color="location",
43
+ )
44
+
45
+ time_graphs = [temp_by_time, temp_by_time_location]
46
+ group_by.change(
47
+ lambda group: [gr.LinePlot(x_bin=None if group == "None" else group)] * len(time_graphs),
48
+ group_by,
49
+ time_graphs
50
+ )
51
+ aggregate.change(
52
+ lambda aggregate: [gr.LinePlot(y_aggregate=aggregate)] * len(time_graphs),
53
+ aggregate,
54
+ time_graphs
55
+ )
56
+
57
+ def rescale(select: gr.SelectData):
58
+ return select.index
59
+ rescale_evt = gr.on([plot.select for plot in time_graphs], rescale, None, [start, end])
60
+
61
+ for trigger in [apply_btn.click, rescale_evt.then]:
62
+ trigger(
63
+ lambda start, end: [gr.LinePlot(x_lim=[start, end])] * len(time_graphs), [start, end], time_graphs
64
+ )
65
+
66
+ price_by_cuisine = gr.LinePlot(
67
+ food_rating_data,
68
+ x="cuisine",
69
+ y="price",
70
+ )
71
+ with gr.Row():
72
+ price_by_rating = gr.LinePlot(
73
+ food_rating_data,
74
+ x="rating",
75
+ y="price",
76
+ )
77
+ price_by_rating_color = gr.LinePlot(
78
+ food_rating_data,
79
+ x="rating",
80
+ y="price",
81
+ color="cuisine",
82
+ color_map={"Italian": "red", "Mexican": "green", "Chinese": "blue"},
83
+ )
84
+
85
+ if __name__ == "__main__":
86
+ line_plots.launch()
87
+
functions/__pycache__/util.cpython-312.pyc CHANGED
Binary files a/functions/__pycache__/util.cpython-312.pyc and b/functions/__pycache__/util.cpython-312.pyc differ
 
functions/util.py CHANGED
@@ -15,6 +15,10 @@ import hopsworks
15
  import hsfs
16
  from pathlib import Path
17
 
 
 
 
 
18
  def get_historical_weather(city, start_date, end_date, latitude, longitude):
19
  # latitude, longitude = get_city_coordinates(city)
20
 
 
15
  import hsfs
16
  from pathlib import Path
17
 
18
+ import sys
19
+ print(sys.path)
20
+
21
+
22
  def get_historical_weather(city, start_date, end_date, latitude, longitude):
23
  # latitude, longitude = get_city_coordinates(city)
24
 
requirements.txt CHANGED
@@ -1,4 +1,5 @@
1
- gradio-datetimerange
2
- gradio
3
  pandas
4
- hopsworks
 
 
1
+ #gradio-datetimerange
2
+ #gradio
3
  pandas
4
+ hopsworks
5
+ streamlit
scheduler.py CHANGED
@@ -5,3 +5,41 @@ app = modal.App('scheduler')
5
  @app.function(schedule=modal.Period(seconds=10))
6
  def update():
7
  print('Updating...')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  @app.function(schedule=modal.Period(seconds=10))
6
  def update():
7
  print('Updating...')
8
+
9
+ # Send dataframe to Streamlit frontend
10
+
11
+
12
+ @app.function()
13
+ def predict():
14
+
15
+ # Extract features
16
+
17
+ # Run model
18
+
19
+ print('Predicting...')
20
+
21
+
22
+ """
23
+ project = hopsworks.login(project=project_name, api_key_value=api_key)
24
+ fs = project.get_feature_store()
25
+ secrets = util.secrets_api(project.name)
26
+
27
+ AQI_API_KEY = secrets.get_secret("AQI_API_KEY").value
28
+ location_str = secrets.get_secret("SENSOR_LOCATION_JSON").value
29
+ location = json.loads(location_str)
30
+
31
+ country=location['country']
32
+ city=location['city']
33
+ street=location['street']
34
+ aqicn_url=location['aqicn_url']
35
+ latitude=location['latitude']
36
+ longitude=location['longitude']
37
+
38
+ today = datetime.date.today()
39
+
40
+ # Retrieve feature groups
41
+ air_quality_fg = fs.get_feature_group(
42
+ name='air_quality',
43
+ version=1,
44
+ )
45
+ """