-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.py
76 lines (50 loc) · 1.92 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import taipy as tp
from taipy.gui import Gui, notify
from taipy.config import Config
import numpy as np
import pandas as pd
BUSINESS_PATH = "data/yelp_business.csv"
# Load the business data using pandas
business_df = pd.read_csv(BUSINESS_PATH)
# Remove quotation marks from the name
business_df.name = business_df.name.str[1:-1]
# Taipy Core
Config.load("config/config.toml")
Config.configure_data_node(id="review_data", read_fct_params=("data/yelp_review.csv",))
scenario_object = Config.scenarios["scenario"]
business_name = business_df.name[0]
reviews = None
def on_selection(state):
"""
Re-runs the scenario when the user selects a business.
Args:
- state: state of the app
"""
notify(state, "info", "Running query...")
business_scenarios = [
s for s in tp.get_scenarios() if s.name == state.business_name
]
if len(business_scenarios) > 0:
scenario = business_scenarios[0]
else:
scenario = tp.create_scenario(scenario_object, name=state.business_name)
scenario.business_name.write(state.business_name)
tp.submit(scenario)
state.reviews = scenario.parsed_reviews.read()
notify(state, "success", "Query finished")
page = """
# Querying **Big Data**{: .color-primary} with Taipy and Dask
## Select a **business**{: .color-primary}
<|{business_name}|selector|lov={list(business_df.name)}|dropdown|on_change=on_selection|>
## Average **stars**{: .color-primary} for that business: <|{"⭐"*int(np.mean(reviews.stars))}|text|raw|>
<|{round(np.mean(reviews.stars),2)}|indicator|value={np.mean(reviews.stars)}|min=1|max=5|width=30%|>
## **Reviews**{: .color-primary} for that business:
<|{reviews}|table|width=100%|>
"""
def on_init(state):
scenario = tp.create_scenario(scenario_object, name=state.business_name)
tp.submit(scenario)
state.reviews = scenario.parsed_reviews.read()
if __name__ == "__main__":
tp.Core().run()
Gui(page).run()