HenryStephen commited on
Commit
8b9797b
1 Parent(s): 2d9baa8

First commit

Browse files
Files changed (5) hide show
  1. app.py +96 -0
  2. data/filtered_table.xlsx +0 -0
  3. data/table.docx +0 -0
  4. data/table.xlsx +0 -0
  5. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+
4
+ # 1. Loading the dataset
5
+ df = pd.read_excel("data/table.xlsx")
6
+
7
+ # 2. Preprocessing the dataset
8
+ df["Bionic prototype"] = df["Bionic prototype"].str.strip()
9
+ df["Materials"] = df["Materials"].str.split(";").apply(lambda x: [material.strip() for material in x])
10
+ df["Method"] = df["Method"].str.split(";").apply(lambda x: [method.strip() for method in x])
11
+ df["Multifunction"] = df["Multifunction"].str.split(";").apply(lambda x: [multifunction.strip() for multifunction in x])
12
+
13
+ # 3. Saving the processed dataset
14
+ # df.to_excel("data/filtered_table.xlsx", index=False)
15
+
16
+ # 4. Extracting a unique list for each column
17
+ bionic_prototype_list = df["Bionic prototype"].unique()
18
+ method_list = df["Method"].explode().unique()
19
+ multifunction_list = df["Multifunction"].explode().unique()
20
+ bionic_prototype_list.sort()
21
+ method_list.sort()
22
+ multifunction_list.sort()
23
+
24
+ with st.sidebar:
25
+ st.slider(
26
+ label="Search results limit",
27
+ min_value=1,
28
+ max_value=50,
29
+ value=20,
30
+ step=1,
31
+ key="limit",
32
+ help="Limit the number of search results",
33
+ )
34
+
35
+ st.multiselect(
36
+ label="Display columns",
37
+ options=["Bionic prototype", "Multifunction", "Method", "Materials", "Res"],
38
+ default=["Bionic prototype", "Multifunction", "Method", "Materials", "Res"],
39
+ help="Select columns to display in the search results",
40
+ key="display_columns",
41
+ )
42
+
43
+ st.title("Bionic Path Selection")
44
+
45
+ st.multiselect(
46
+ label="Multifunction",
47
+ options=multifunction_list,
48
+ default=[],
49
+ help="Select the multifunction to display in the search results",
50
+ placeholder="Select the multifunction to display in the search results",
51
+ key="multifunction_option"
52
+ )
53
+
54
+ st.session_state.disabled = False if len(st.session_state.multifunction_option) > 0 else True
55
+
56
+ left_col, right_col = st.columns(2)
57
+ with left_col:
58
+ st.selectbox(
59
+ label="Bionic prototype",
60
+ options=bionic_prototype_list,
61
+ help="Select the bionic prototype to display in the search results",
62
+ placeholder="Select the bionic prototype to display in the search results",
63
+ index=None,
64
+ key="bionic_prototype_option",
65
+ disabled=st.session_state.disabled
66
+ )
67
+ with right_col:
68
+ st.multiselect(
69
+ label="Method",
70
+ options=method_list,
71
+ default=[],
72
+ help="Select the method to display in the search results",
73
+ placeholder="Select the method to display in the search results",
74
+ key="method_option",
75
+ disabled=st.session_state.disabled
76
+ )
77
+
78
+ search = st.button("Search")
79
+ if search:
80
+ multifunction_option = st.session_state.multifunction_option
81
+ bionic_prototype_option = st.session_state.bionic_prototype_option
82
+ method_option = st.session_state.method_option
83
+
84
+ # Filter the multifunction column
85
+ filtered_df = df[
86
+ df["Multifunction"].apply(lambda x: all(multifunction in x for multifunction in multifunction_option))]
87
+ # Filter the bionic prototype column
88
+ filtered_df = filtered_df[filtered_df["Bionic prototype"] == bionic_prototype_option] \
89
+ if (bionic_prototype_option is not None and not st.session_state.disabled and not filtered_df.empty) \
90
+ else filtered_df
91
+ # Filter the method column
92
+ filtered_df = filtered_df[filtered_df["Method"].apply(lambda x: any(method in x for method in method_option))] \
93
+ if (len(method_option) > 0 and not st.session_state.disabled and not filtered_df.empty) \
94
+ else filtered_df
95
+
96
+ st.dataframe(filtered_df[st.session_state.display_columns].head(st.session_state.limit))
data/filtered_table.xlsx ADDED
Binary file (7.67 kB). View file
 
data/table.docx ADDED
Binary file (37 kB). View file
 
data/table.xlsx ADDED
Binary file (13 kB). View file
 
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ pandas
2
+ streamlit
3
+ openpyxl