RichardErkhov commited on
Commit
4b65a10
·
verified ·
1 Parent(s): 5996317

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +94 -16
app.py CHANGED
@@ -11,15 +11,12 @@ CHUNK_SIZE = 1000
11
 
12
  # Clickable links function
13
  def clickable(x, which_one):
 
 
14
  if which_one == "models":
15
- if x not in ["Not Found", "Unknown"]:
16
- return f'<a target="_blank" href="https://huggingface.co/{x}" style="color: var(--link-text-color); text-decoration: underline;text-decoration-style: dotted;">{x}</a>'
17
- else:
18
- return "Not Found"
19
  else:
20
- if x != "Not Found":
21
- return f'<a target="_blank" href="https://huggingface.co/{which_one}/{x}" style="color: var(--link-text-color); text-decoration: underline;text-decoration-style: dotted;">{x}</a>'
22
- return "Not Found"
23
 
24
  # Fetch models and return a DataFrame with clickable links
25
  def fetch_models():
@@ -37,7 +34,7 @@ def fetch_models():
37
  "Last Modified": model.last_modified.isoformat() if model.last_modified else "N/A",
38
  })
39
  df = pd.DataFrame(data)
40
- # Apply clickable links
41
  df["Model ID"] = df["Model ID"].apply(lambda x: clickable(x, "models"))
42
  df["Author Name"] = df["Author Name"].apply(lambda x: clickable(x, "models"))
43
  return df
@@ -45,6 +42,7 @@ def fetch_models():
45
  # Prepare authors DataFrame
46
  def prepare_authors_df(models_df):
47
  authors_df = models_df.copy()
 
48
  authors_df["Clean Author Name"] = authors_df["Author Name"].str.extract(r'href="https://huggingface\.co/(.*?)"')
49
 
50
  grouped = authors_df.groupby("Clean Author Name").agg(
@@ -54,6 +52,7 @@ def prepare_authors_df(models_df):
54
  ).reset_index()
55
 
56
  grouped.rename(columns={"Clean Author Name": "Author Name"}, inplace=True)
 
57
  return grouped.sort_values(by="Models_Count", ascending=False)
58
 
59
  all_models_df = fetch_models().sort_values(by="Downloads (30d)", ascending=False)
@@ -64,11 +63,60 @@ total_models_count = len(all_models_df)
64
  total_downloads = all_models_df["Downloads (30d)"].sum()
65
  total_likes = all_models_df["Likes"].sum()
66
 
67
- def update_model_table(start_idx):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
  new_end = start_idx + CHUNK_SIZE
69
- combined_df = all_models_df.iloc[:new_end].copy()
70
  return combined_df, new_end
71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  with gr.Blocks() as demo:
73
  gr.Markdown(f"""
74
  # 🚀GGUF Tracker🚀
@@ -86,25 +134,55 @@ with gr.Blocks() as demo:
86
 
87
  with gr.Tabs():
88
  with gr.TabItem("Models"):
 
 
 
 
 
 
89
  model_table = gr.DataFrame(
90
  value=all_models_df.iloc[:CHUNK_SIZE],
91
- interactive=True,
92
- label="GGUF Models",
93
  wrap=True,
94
  datatype=["markdown", "markdown", "number", "number", "str", "str"]
95
  )
96
  load_more_button = gr.Button("Load More Models")
 
 
97
  start_idx = gr.State(value=CHUNK_SIZE)
 
98
 
99
- load_more_button.click(fn=update_model_table, inputs=start_idx, outputs=[model_table, start_idx])
 
 
 
 
 
100
 
101
  with gr.TabItem("Authors"):
102
- gr.DataFrame(
 
 
 
 
 
 
103
  value=authors_df,
104
  interactive=False,
105
- label="Authors",
106
  wrap=True,
107
- datatype=["str", "number", "number", "number"]
 
 
 
 
 
 
 
 
 
 
108
  )
109
 
110
  demo.launch()
 
11
 
12
  # Clickable links function
13
  def clickable(x, which_one):
14
+ if x in ["Not Found", "Unknown"]:
15
+ return "Not Found"
16
  if which_one == "models":
17
+ return f'<a target="_blank" href="https://huggingface.co/{x}" style="color: var(--link-text-color); text-decoration: underline;text-decoration-style: dotted;">{x}</a>'
 
 
 
18
  else:
19
+ return f'<a target="_blank" href="https://huggingface.co/{which_one}/{x}" style="color: var(--link-text-color); text-decoration: underline;text-decoration-style: dotted;">{x}</a>'
 
 
20
 
21
  # Fetch models and return a DataFrame with clickable links
22
  def fetch_models():
 
34
  "Last Modified": model.last_modified.isoformat() if model.last_modified else "N/A",
35
  })
36
  df = pd.DataFrame(data)
37
+ # Apply clickable links to models and authors
38
  df["Model ID"] = df["Model ID"].apply(lambda x: clickable(x, "models"))
39
  df["Author Name"] = df["Author Name"].apply(lambda x: clickable(x, "models"))
40
  return df
 
42
  # Prepare authors DataFrame
43
  def prepare_authors_df(models_df):
44
  authors_df = models_df.copy()
45
+ # Extract the author name from the href in the clickable link
46
  authors_df["Clean Author Name"] = authors_df["Author Name"].str.extract(r'href="https://huggingface\.co/(.*?)"')
47
 
48
  grouped = authors_df.groupby("Clean Author Name").agg(
 
52
  ).reset_index()
53
 
54
  grouped.rename(columns={"Clean Author Name": "Author Name"}, inplace=True)
55
+ grouped["Author Name"] = grouped["Author Name"].apply(lambda x: clickable(x, "models"))
56
  return grouped.sort_values(by="Models_Count", ascending=False)
57
 
58
  all_models_df = fetch_models().sort_values(by="Downloads (30d)", ascending=False)
 
63
  total_downloads = all_models_df["Downloads (30d)"].sum()
64
  total_likes = all_models_df["Likes"].sum()
65
 
66
+ def apply_model_filters(search_query, min_downloads, min_likes):
67
+ df = all_models_df.copy()
68
+
69
+ # Extract visible text for filtering purposes:
70
+ visible_model_id = df["Model ID"].str.extract(r'>(.*?)<')[0]
71
+ visible_author_name = df["Author Name"].str.extract(r'>(.*?)<')[0]
72
+
73
+ # Search filter
74
+ if search_query.strip():
75
+ mask = (visible_model_id.str.contains(search_query, case=False, na=False)) | \
76
+ (visible_author_name.str.contains(search_query, case=False, na=False))
77
+ df = df[mask]
78
+
79
+ # Minimum downloads filter
80
+ if min_downloads is not None and min_downloads > 0:
81
+ df = df[df["Downloads (30d)"] >= min_downloads]
82
+
83
+ # Minimum likes filter
84
+ if min_likes is not None and min_likes > 0:
85
+ df = df[df["Likes"] >= min_likes]
86
+
87
+ return df
88
+
89
+ def filter_models(search_query, min_downloads, min_likes):
90
+ filtered = apply_model_filters(search_query, min_downloads, min_likes)
91
+ return filtered.iloc[:CHUNK_SIZE], CHUNK_SIZE, filtered
92
+
93
+ def update_model_table(start_idx, filtered_df):
94
  new_end = start_idx + CHUNK_SIZE
95
+ combined_df = filtered_df.iloc[:new_end].copy()
96
  return combined_df, new_end
97
 
98
+ def apply_author_filters(search_query, min_author_downloads, min_author_likes):
99
+ df = authors_df.copy()
100
+
101
+ # Extract visible text for author filtering:
102
+ visible_author_name = df["Author Name"].str.extract(r'>(.*?)<')[0]
103
+
104
+ # Search filter for authors
105
+ if search_query.strip():
106
+ mask = visible_author_name.str.contains(search_query, case=False, na=False)
107
+ df = df[mask]
108
+
109
+ # Minimum total downloads filter
110
+ if min_author_downloads is not None and min_author_downloads > 0:
111
+ df = df[df["Total_Downloads"] >= min_author_downloads]
112
+
113
+ # Minimum total likes filter
114
+ if min_author_likes is not None and min_author_likes > 0:
115
+ df = df[df["Total_Likes"] >= min_author_likes]
116
+
117
+ return df
118
+
119
+
120
  with gr.Blocks() as demo:
121
  gr.Markdown(f"""
122
  # 🚀GGUF Tracker🚀
 
134
 
135
  with gr.Tabs():
136
  with gr.TabItem("Models"):
137
+ with gr.Row():
138
+ search_query = gr.Textbox(label="Search (by Model ID or Author Name)")
139
+ min_downloads = gr.Number(label="Min Downloads (30d)", value=0)
140
+ min_likes = gr.Number(label="Min Likes", value=0)
141
+
142
+ filter_button = gr.Button("Apply Filters")
143
  model_table = gr.DataFrame(
144
  value=all_models_df.iloc[:CHUNK_SIZE],
145
+ interactive=False,
146
+ label="GGUF Models (Click column headers to sort)",
147
  wrap=True,
148
  datatype=["markdown", "markdown", "number", "number", "str", "str"]
149
  )
150
  load_more_button = gr.Button("Load More Models")
151
+
152
+ # States
153
  start_idx = gr.State(value=CHUNK_SIZE)
154
+ filtered_df_state = gr.State(value=all_models_df) # holds the currently filtered df
155
 
156
+ filter_button.click(
157
+ fn=filter_models,
158
+ inputs=[search_query, min_downloads, min_likes],
159
+ outputs=[model_table, start_idx, filtered_df_state]
160
+ )
161
+ load_more_button.click(fn=update_model_table, inputs=[start_idx, filtered_df_state], outputs=[model_table, start_idx])
162
 
163
  with gr.TabItem("Authors"):
164
+ with gr.Row():
165
+ author_search_query = gr.Textbox(label="Search by Author Name")
166
+ min_author_downloads = gr.Number(label="Min Total Downloads", value=0)
167
+ min_author_likes = gr.Number(label="Min Total Likes", value=0)
168
+
169
+ author_filter_button = gr.Button("Apply Filters")
170
+ author_table = gr.DataFrame(
171
  value=authors_df,
172
  interactive=False,
173
+ label="Authors (Click column headers to sort)",
174
  wrap=True,
175
+ datatype=["markdown", "number", "number", "number"]
176
+ )
177
+
178
+ def filter_authors(author_search_query, min_author_downloads, min_author_likes):
179
+ filtered_authors = apply_author_filters(author_search_query, min_author_downloads, min_author_likes)
180
+ return filtered_authors
181
+
182
+ author_filter_button.click(
183
+ fn=filter_authors,
184
+ inputs=[author_search_query, min_author_downloads, min_author_likes],
185
+ outputs=author_table
186
  )
187
 
188
  demo.launch()