lambdaofgod commited on
Commit
4a400da
1 Parent(s): 9de44a7

app refactor

Browse files
Files changed (1) hide show
  1. app.py +40 -22
app.py CHANGED
@@ -2,30 +2,48 @@ import pandas as pd
2
  import streamlit as st
3
  import math
4
 
5
- models_df = pd.read_csv("models_with_readmes.csv").dropna(subset=["readme"])
6
 
7
- st.title("Huggingface model explorer")
8
- st.text(f"search {len(models_df)} models by name or readme")
9
- st.text("note that there are many more models but here we only show those with readme")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
- col1, col2, col3 = st.columns(3)
12
- query = col1.text_input("model name query", value="")
13
- readme_query = col2.text_input("readme query", value="")
14
 
15
- selected_models_df = models_df[
16
- models_df["readme"].str.contains(readme_query)
17
- & models_df["modelId"].str.contains(query)
18
- ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
  n_per_page = 10
21
- slider = col3.number_input("page", 0, math.ceil(len(selected_models_df) / 10))
22
- selected_models_df_subset = selected_models_df.iloc[
23
- slider * n_per_page : (slider + 1) * n_per_page
24
- ]
25
- st.write(f"matched {len(selected_models_df)} models")
26
-
27
- for i, (model_name, tag, readme) in enumerate(
28
- selected_models_df_subset[["modelId", "pipeline_tag", "readme"]].itertuples(index=False)
29
- ):
30
- with st.expander(f"{model_name} ({tag})"):
31
- st.write(readme)
 
2
  import streamlit as st
3
  import math
4
 
 
5
 
6
+ def setup_page():
7
+ st.title("Huggingface model explorer")
8
+ st.text(f"search {len(models_df)} models by name or readme")
9
+ st.text(
10
+ "note that there are many more models but here we only show those with readme"
11
+ )
12
+
13
+
14
+ def setup_inputs():
15
+ col1, col2, col3 = st.columns(3)
16
+ query = col1.text_input("model name query", value="")
17
+ readme_query = col2.text_input("readme query", value="")
18
+ return query, readme_query, col3
19
+
20
+
21
+ def get_selected_models_df(query, readme_query):
22
+ return models_df[
23
+ models_df["readme"].str.lower().str.contains(readme_query)
24
+ & models_df["modelId"].str.lower().str.contains(query)
25
+ ]
26
 
 
 
 
27
 
28
+ def show_paged_selected_model_info(models_df, page_col):
29
+ page = page_col.number_input("page", 0, math.ceil(len(selected_models_df) / 10))
30
+ selected_models_df_subset = models_df.iloc[
31
+ page * n_per_page : (page+ 1) * n_per_page
32
+ ]
33
+ st.write(f"found {len(selected_models_df)} models")
34
+ for (model_name, tag, readme) in selected_models_df_subset[
35
+ ["modelId", "pipeline_tag", "readme"]
36
+ ].itertuples(index=False):
37
+ with st.expander(f"{model_name} ({tag})"):
38
+ st.write(readme)
39
+
40
+
41
+ models_df = pd.read_csv("models_with_readmes.csv").dropna(subset=["readme"])
42
+
43
+ setup_page()
44
+ query, readme_query, page_col = setup_inputs()
45
+ selected_models_df = get_selected_models_df(query, readme_query)
46
 
47
  n_per_page = 10
48
+
49
+ show_paged_selected_model_info(selected_models_df, page_col)