Skip to content

Commit

Permalink
Fix format
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianJacta committed Sep 2, 2024
1 parent 0372352 commit 698fe16
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 30 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
src/.taipy
src/user_data
88 changes: 58 additions & 30 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,47 +5,56 @@

# Create a Taipy App that will output the 7 best movies for a genre


# Filter function for Task
def filtering_genre(initial_dataset: pd.DataFrame, selected_genre):
filtered_dataset = initial_dataset[initial_dataset['genres'].str.contains(selected_genre)]
filtered_data = filtered_dataset.nlargest(7, 'Popularity %')
filtered_dataset = initial_dataset[
initial_dataset["genres"].str.contains(selected_genre)
]
filtered_data = filtered_dataset.nlargest(7, "Popularity %")
return filtered_data


# Callback definition
def modify_df(state):
scenario.selected_genre_node.write(state.selected_genre)
tp.submit(scenario)
state.df = scenario.filtered_data.read()
state.df = scenario.filtered_data.read()


if __name__ == "__main__":
# Taipy Core - backend definition

# Input Data Nodes configuration
initial_dataset_cfg = Config.configure_data_node(id="initial_dataset",
storage_type="csv",
path="data/data.csv",
scope=Scope.GLOBAL)
initial_dataset_cfg = Config.configure_data_node(
id="initial_dataset",
storage_type="csv",
path="data/data.csv",
scope=Scope.GLOBAL,
)

selected_genre_cfg = Config.configure_data_node(id="selected_genre_node",
default_data="ACTION",
scope=Scope.GLOBAL)
selected_genre_cfg = Config.configure_data_node(
id="selected_genre_node", default_data="ACTION", scope=Scope.GLOBAL
)

# Output Data Node configuration
filtered_data_cfg = Config.configure_data_node(id="filtered_data",
scope=Scope.GLOBAL)
filtered_data_cfg = Config.configure_data_node(
id="filtered_data", scope=Scope.GLOBAL
)

# Task configuration
filter_task_cfg = Config.configure_task(id="filter_genre",
function=filtering_genre,
input=[initial_dataset_cfg, selected_genre_cfg],
output=filtered_data_cfg,
skippable=True)

filter_task_cfg = Config.configure_task(
id="filter_genre",
function=filtering_genre,
input=[initial_dataset_cfg, selected_genre_cfg],
output=filtered_data_cfg,
skippable=True,
)

# Scenario configuration
scenario_cfg = Config.configure_scenario(id="scenario", task_configs=[filter_task_cfg])
scenario_cfg = Config.configure_scenario(
id="scenario", task_configs=[filter_task_cfg]
)

# Run of the Taipy Core service
tp.Orchestrator().run()
Expand All @@ -56,25 +65,44 @@ def modify_df(state):
# Taipy GUI- front end definition

# Get list of genres
list_genres = ['Action', 'Adventure', 'Animation', 'Children', 'Comedy', 'Fantasy', 'IMAX', 'Romance',
'Sci-FI', 'Western', 'Crime', 'Mystery', 'Drama', 'Horror', 'Thriller', 'Film-Noir',
'War', 'Musical', 'Documentary']
list_genres = [
"Action",
"Adventure",
"Animation",
"Children",
"Comedy",
"Fantasy",
"IMAX",
"Romance",
"Sci-FI",
"Western",
"Crime",
"Mystery",
"Drama",
"Horror",
"Thriller",
"Film-Noir",
"War",
"Musical",
"Documentary",
]

# Initialization of variables
df = pd.DataFrame(columns=['Title', 'Popularity %'])
df = pd.DataFrame(columns=["Title", "Popularity %"])
selected_genre = None

with tgb.Page() as movie_genre_app:
tgb.text("# Film recommendation", mode="md")

tgb.text("## Choose your favorite genre")
tgb.selector("{selected_genre}",
lov=list_genres,
on_change=modify_df,
dropdown=True)

tgb.text("## Choose your favorite genre", mode="md")
tgb.selector(
"{selected_genre}", lov=list_genres, on_change=modify_df, dropdown=True
)

tgb.text("## Here are the top 7 picks", mode="md")
tgb.chart("{df}", x="Title", y="Popularity %", type="bar", title="Film Popularity")
tgb.chart(
"{df}", x="Title", y="Popularity %", type="bar", title="Film Popularity"
)

# run the app
Gui(page=movie_genre_app).run()

0 comments on commit 698fe16

Please sign in to comment.