Upload 3 files
Browse files- app.py +16 -16
- hfsearch.py +23 -22
app.py
CHANGED
@@ -14,7 +14,7 @@ with gr.Blocks(theme="NoCrypt/miku", fill_width=True, css=CSS) as demo:
|
|
14 |
gr.Markdown("# Search Hugging Faceπ€", elem_classes="title")
|
15 |
with gr.Column():
|
16 |
search_result = gr.State(value=HFSearchResult())
|
17 |
-
with gr.Tab("
|
18 |
with gr.Group():
|
19 |
with gr.Row(equal_height=True):
|
20 |
repo_types = gr.CheckboxGroup(label="Repo type", choices=["model", "dataset", "space", "collection"], value=["model", "dataset", "space"])
|
@@ -67,7 +67,7 @@ with gr.Blocks(theme="NoCrypt/miku", fill_width=True, css=CSS) as demo:
|
|
67 |
with gr.Row(equal_height=True):
|
68 |
show_labels = gr.CheckboxGroup(label="Show items", choices=get_labels(), value=get_valid_labels())
|
69 |
run_button = gr.Button("Search", variant="primary")
|
70 |
-
with gr.Tab("
|
71 |
with gr.Group():
|
72 |
with gr.Row(equal_height=True):
|
73 |
infer_repo_types = gr.CheckboxGroup(label="Repo type", choices=["model", "dataset", "space"], value=["model"], visible=False)
|
@@ -78,7 +78,20 @@ with gr.Blocks(theme="NoCrypt/miku", fill_width=True, css=CSS) as demo:
|
|
78 |
infer_gated_status = gr.Radio(label="Gated status", choices=["gated", "non-gated", "all"], value="all")
|
79 |
infer_appr_status = gr.CheckboxGroup(label="Approval method", choices=["auto", "manual"], value=["auto", "manual"])
|
80 |
infer_run_button = gr.Button("Search", variant="primary")
|
81 |
-
with gr.Tab("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
with gr.Group():
|
83 |
with gr.Row(equal_height=True):
|
84 |
#rec_repo_id = gr.Textbox(label="Repo ID", info="Input your favorite repo", value="")
|
@@ -92,19 +105,6 @@ with gr.Blocks(theme="NoCrypt/miku", fill_width=True, css=CSS) as demo:
|
|
92 |
with gr.Row(equal_height=True):
|
93 |
rec_show_labels = gr.CheckboxGroup(label="Show items", choices=get_labels(), value=get_valid_labels())
|
94 |
rec_run_button = gr.Button("Search", variant="primary")
|
95 |
-
with gr.Tab("Find collections"):
|
96 |
-
with gr.Group():
|
97 |
-
with gr.Row(equal_height=True):
|
98 |
-
#rec_repo_id = gr.Textbox(label="Repo ID", info="Input your favorite repo", value="")
|
99 |
-
col_repo_id = HuggingfaceHubSearch(label="Repo ID or User ID", placeholder="Input your favorite Repo ID or User ID", search_type=["model", "dataset", "space", "user"],
|
100 |
-
sumbit_on_select=False)
|
101 |
-
col_sort = gr.Dropdown(label="Sort", choices=["last_modified", "trending_score", "likes"], value="likes")
|
102 |
-
with gr.Row(equal_height=True):
|
103 |
-
col_repo_limit = gr.Number(label="Limit for repos", value=50, step=1, minimum=1, maximum=100)
|
104 |
-
col_user_limit = gr.Number(label="Limit for users", value=10, step=1, minimum=0, maximum=50)
|
105 |
-
with gr.Accordion("Advanced", open=False):
|
106 |
-
col_show_labels = gr.CheckboxGroup(label="Show items", choices=get_labels(), value=get_valid_labels())
|
107 |
-
col_run_button = gr.Button("Search", variant="primary")
|
108 |
with gr.Group():
|
109 |
with gr.Accordion("Filter", open=False):
|
110 |
hide_labels = gr.CheckboxGroup(label="Hide items", choices=[], value=[], visible=False)
|
|
|
14 |
gr.Markdown("# Search Hugging Faceπ€", elem_classes="title")
|
15 |
with gr.Column():
|
16 |
search_result = gr.State(value=HFSearchResult())
|
17 |
+
with gr.Tab("Search"):
|
18 |
with gr.Group():
|
19 |
with gr.Row(equal_height=True):
|
20 |
repo_types = gr.CheckboxGroup(label="Repo type", choices=["model", "dataset", "space", "collection"], value=["model", "dataset", "space"])
|
|
|
67 |
with gr.Row(equal_height=True):
|
68 |
show_labels = gr.CheckboxGroup(label="Show items", choices=get_labels(), value=get_valid_labels())
|
69 |
run_button = gr.Button("Search", variant="primary")
|
70 |
+
with gr.Tab("Inference API models"):
|
71 |
with gr.Group():
|
72 |
with gr.Row(equal_height=True):
|
73 |
infer_repo_types = gr.CheckboxGroup(label="Repo type", choices=["model", "dataset", "space"], value=["model"], visible=False)
|
|
|
78 |
infer_gated_status = gr.Radio(label="Gated status", choices=["gated", "non-gated", "all"], value="all")
|
79 |
infer_appr_status = gr.CheckboxGroup(label="Approval method", choices=["auto", "manual"], value=["auto", "manual"])
|
80 |
infer_run_button = gr.Button("Search", variant="primary")
|
81 |
+
with gr.Tab("Collections"):
|
82 |
+
with gr.Group():
|
83 |
+
with gr.Row(equal_height=True):
|
84 |
+
#rec_repo_id = gr.Textbox(label="Repo ID", info="Input your favorite repo", value="")
|
85 |
+
col_repo_id = HuggingfaceHubSearch(label="Repo ID or User ID", placeholder="Input your favorite Repo ID or User ID", search_type=["model", "dataset", "space", "user"],
|
86 |
+
sumbit_on_select=False)
|
87 |
+
col_sort = gr.Dropdown(label="Sort", choices=["last_modified", "trending_score", "likes"], value="likes")
|
88 |
+
with gr.Row(equal_height=True):
|
89 |
+
col_repo_limit = gr.Number(label="Limit for repos", value=50, step=1, minimum=1, maximum=100)
|
90 |
+
col_user_limit = gr.Number(label="Limit for users", value=10, step=1, minimum=0, maximum=50)
|
91 |
+
with gr.Accordion("Advanced", open=False):
|
92 |
+
col_show_labels = gr.CheckboxGroup(label="Show items", choices=get_labels(), value=get_valid_labels())
|
93 |
+
col_run_button = gr.Button("Search", variant="primary")
|
94 |
+
with gr.Tab("Recommended repos"):
|
95 |
with gr.Group():
|
96 |
with gr.Row(equal_height=True):
|
97 |
#rec_repo_id = gr.Textbox(label="Repo ID", info="Input your favorite repo", value="")
|
|
|
105 |
with gr.Row(equal_height=True):
|
106 |
rec_show_labels = gr.CheckboxGroup(label="Show items", choices=get_labels(), value=get_valid_labels())
|
107 |
rec_run_button = gr.Button("Search", variant="primary")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
with gr.Group():
|
109 |
with gr.Accordion("Filter", open=False):
|
110 |
hide_labels = gr.CheckboxGroup(label="Hide items", choices=[], value=[], visible=False)
|
hfsearch.py
CHANGED
@@ -21,7 +21,7 @@ TYPES_URL = {"model": "https://huggingface.co/models", "dataset": "https://huggi
|
|
21 |
TYPES_DESC = " / ".join([f"[{v}={k}]({TYPES_URL.get(k, 'https://hf.co')})" for k, v in zip(list(TYPES_SHORT.keys()), list(TYPES_SHORT.values()))])
|
22 |
|
23 |
RESULT_ITEMS = {
|
24 |
-
"
|
25 |
"ID": [2, "markdown", True, "40%"],
|
26 |
"User": [4, "str", False],
|
27 |
"Name": [5, "str", False],
|
@@ -318,7 +318,7 @@ class HFSearchResult():
|
|
318 |
elif mode == "PC": self.phone_mode = False
|
319 |
|
320 |
def get_show_labels(self):
|
321 |
-
return ["
|
322 |
|
323 |
def _set(self, data, label: str):
|
324 |
self.labels.set(label)
|
@@ -339,7 +339,7 @@ class HFSearchResult():
|
|
339 |
elif isinstance(i, PaperInfo): type = "paper"
|
340 |
elif isinstance(i, Collection): type = "collection"
|
341 |
else: return
|
342 |
-
self._set(type, "
|
343 |
self._set("", "Emoji")
|
344 |
if type in ["space", "model", "dataset"]:
|
345 |
self._set(i.id, "ID")
|
@@ -520,18 +520,18 @@ class HFSearchResult():
|
|
520 |
if "AllDLs" in columns: sdf = rank_df(sdf, df, "AllDLs")
|
521 |
if "DLs" in columns: sdf = rank_df(sdf, df, "DLs")
|
522 |
if "Status" in columns:
|
523 |
-
sdf.loc[df["Status"] == "warm", ["
|
524 |
-
sdf.loc[df["Status"] == "cold", ["
|
525 |
if "Gated" in columns:
|
526 |
sdf.loc[df["Gated"] == "auto", ["Gated"]] = 'color: dodgerblue'
|
527 |
sdf.loc[df["Gated"] == "manual", ["Gated"]] = 'color: crimson'
|
528 |
if "Stage" in columns and "Hardware" in columns:
|
529 |
-
sdf.loc[(df["Stage"] == "RUNNING") & (df["Hardware"] != "zero-a10g") & (df["Hardware"] != "cpu-basic") & (df["Hardware"]), ["Hardware", "
|
530 |
-
sdf.loc[(df["Stage"] == "RUNNING") & (df["Hardware"] == "zero-a10g"), ["Hardware", "
|
531 |
-
sdf.loc[(df["
|
532 |
-
sdf.loc[(df["
|
533 |
sdf.loc[df["Stage"] == "RUNNING", ["Stage"]] = 'color: lime'
|
534 |
-
if "NFAA" in columns: sdf.loc[df["NFAA"] == "True", ["
|
535 |
show_columns = x.copy().columns
|
536 |
style_columns = sdf.columns
|
537 |
drop_columns = [c for c in style_columns if c not in show_columns]
|
@@ -540,24 +540,24 @@ class HFSearchResult():
|
|
540 |
|
541 |
def id_to_md(df: pd.DataFrame, verbose=False):
|
542 |
columns = list(df.index)
|
543 |
-
if df["
|
544 |
-
elif df["
|
545 |
-
elif df["
|
546 |
else: id = f'### [{df["ID"]}]({df["URL"]}){df["Emoji"]}'
|
547 |
if verbose:
|
548 |
l = []
|
549 |
if "NFAA" in columns and df["NFAA"] == "True": l.append('π€')
|
550 |
if "Likes" in columns and df["Likes"] > 0: l.append(f'π:{df["Likes"]}')
|
551 |
-
if df["
|
552 |
if "Trending" in columns and df["Trending"] > 0: l.append(f'trend:{df["Trending"]}')
|
553 |
-
if df["
|
554 |
if "DLs" in columns and df["DLs"] > 0: l.append(f'DL:{df["DLs"]}')
|
555 |
if "Gated" in columns and df["Gated"] in ["manual", "auto"]: l.append(f'π:{df["Gated"]}')
|
556 |
-
if df["
|
557 |
if "Status" in columns:
|
558 |
if df["Status"] == "warm": l.append(f'inference:π₯')
|
559 |
elif df["Status"] == "cold": l.append(f'inference:π§')
|
560 |
-
if df["
|
561 |
if "Hardware" in columns and df["Hardware"] in SPACE_HARDWARES and df["Hardware"] != "cpu-basic": l.append(f'{df["Hardware"]}')
|
562 |
if "SDK" in columns: l.append(f'{df["SDK"]}')
|
563 |
if "Stage" in columns and df["Stage"] in SPACE_STAGES_EMOJI.keys(): l.append(f'{SPACE_STAGES_EMOJI[df["Stage"]]}')
|
@@ -567,7 +567,7 @@ class HFSearchResult():
|
|
567 |
def shorten_type(df: pd.DataFrame, shorten=False):
|
568 |
if shorten:
|
569 |
for k, v in TYPES_SHORT.items():
|
570 |
-
if df["
|
571 |
|
572 |
def to_emoji(df: pd.DataFrame, label: str, key: str, emoji: str):
|
573 |
if df[label] == key: return f'{df["Emoji"]}{emoji}' if df["Emoji"] else f' {emoji}'
|
@@ -582,7 +582,7 @@ class HFSearchResult():
|
|
582 |
|
583 |
def format_md_df(df: pd.DataFrame, verbose=False):
|
584 |
df["ID"] = df.apply(id_to_md, axis=1, verbose=verbose)
|
585 |
-
df["
|
586 |
return df
|
587 |
|
588 |
hide_labels = [l for l in labels if l in self.hide_labels or l not in self.get_show_labels()]
|
@@ -630,7 +630,7 @@ class HFSearchResult():
|
|
630 |
if key in SORT_PARAM_TO_ITEM.keys(): key = SORT_PARAM_TO_ITEM[key]
|
631 |
types = set()
|
632 |
for i in self.item_list:
|
633 |
-
if "
|
634 |
if "paper" in types: return
|
635 |
if key in ["DLs", "AllDLs"] and ("space" in types or "collection" in types): key = "Likes"
|
636 |
if not key in self.labels.get()[0]: key = "Likes"
|
@@ -646,10 +646,11 @@ class HFSearchResult():
|
|
646 |
df, labels, label_types = self.get()
|
647 |
widths = self.labels.get_widths()
|
648 |
if self.phone_mode:
|
649 |
-
widths["
|
650 |
widths["ID"] = "90%"
|
651 |
column_widths = [widths[l] for l in labels]
|
652 |
-
if self.phone_mode:
|
|
|
653 |
return gr.update(type="pandas", value=df, headers=labels, datatype=label_types, column_widths=column_widths, wrap=True, show_label=False)
|
654 |
|
655 |
def get_gr_hide_labels(self):
|
|
|
21 |
TYPES_DESC = " / ".join([f"[{v}={k}]({TYPES_URL.get(k, 'https://hf.co')})" for k, v in zip(list(TYPES_SHORT.keys()), list(TYPES_SHORT.values()))])
|
22 |
|
23 |
RESULT_ITEMS = {
|
24 |
+
"T": [1, "str", True],
|
25 |
"ID": [2, "markdown", True, "40%"],
|
26 |
"User": [4, "str", False],
|
27 |
"Name": [5, "str", False],
|
|
|
318 |
elif mode == "PC": self.phone_mode = False
|
319 |
|
320 |
def get_show_labels(self):
|
321 |
+
return ["T", "ID"] if self.phone_mode else self.show_labels
|
322 |
|
323 |
def _set(self, data, label: str):
|
324 |
self.labels.set(label)
|
|
|
339 |
elif isinstance(i, PaperInfo): type = "paper"
|
340 |
elif isinstance(i, Collection): type = "collection"
|
341 |
else: return
|
342 |
+
self._set(type, "T")
|
343 |
self._set("", "Emoji")
|
344 |
if type in ["space", "model", "dataset"]:
|
345 |
self._set(i.id, "ID")
|
|
|
520 |
if "AllDLs" in columns: sdf = rank_df(sdf, df, "AllDLs")
|
521 |
if "DLs" in columns: sdf = rank_df(sdf, df, "DLs")
|
522 |
if "Status" in columns:
|
523 |
+
sdf.loc[df["Status"] == "warm", ["T", "Status"]] = 'color: orange'
|
524 |
+
sdf.loc[df["Status"] == "cold", ["T", "Status"]] = 'color: dodgerblue'
|
525 |
if "Gated" in columns:
|
526 |
sdf.loc[df["Gated"] == "auto", ["Gated"]] = 'color: dodgerblue'
|
527 |
sdf.loc[df["Gated"] == "manual", ["Gated"]] = 'color: crimson'
|
528 |
if "Stage" in columns and "Hardware" in columns:
|
529 |
+
sdf.loc[(df["Stage"] == "RUNNING") & (df["Hardware"] != "zero-a10g") & (df["Hardware"] != "cpu-basic") & (df["Hardware"]), ["Hardware", "T"]] = 'color: lime'
|
530 |
+
sdf.loc[(df["Stage"] == "RUNNING") & (df["Hardware"] == "zero-a10g"), ["Hardware", "T"]] = 'color: limegreen'
|
531 |
+
sdf.loc[(df["T"] == "space") & (df["Stage"] != "RUNNING")] = 'opacity: 0.5'
|
532 |
+
sdf.loc[(df["T"] == "space") & (df["Stage"] != "RUNNING"), ["T"]] = 'color: crimson'
|
533 |
sdf.loc[df["Stage"] == "RUNNING", ["Stage"]] = 'color: lime'
|
534 |
+
if "NFAA" in columns: sdf.loc[df["NFAA"] == "True", ["T"]] = 'background-color: hotpink'
|
535 |
show_columns = x.copy().columns
|
536 |
style_columns = sdf.columns
|
537 |
drop_columns = [c for c in style_columns if c not in show_columns]
|
|
|
540 |
|
541 |
def id_to_md(df: pd.DataFrame, verbose=False):
|
542 |
columns = list(df.index)
|
543 |
+
if df["T"] == "collection": id = f'### [{df["User"]}/{df["Name"]}]({df["URL"]}){df["Emoji"]}'
|
544 |
+
elif df["T"] == "space": id = f'### [{df["Name"]} ({df["ID"]})]({df["URL"]}){df["Emoji"]}'
|
545 |
+
elif df["T"] == "paper": id = f'### [{df["Name"]} (arxiv:{df["ID"]})]({df["URL"]}){df["Emoji"]}'
|
546 |
else: id = f'### [{df["ID"]}]({df["URL"]}){df["Emoji"]}'
|
547 |
if verbose:
|
548 |
l = []
|
549 |
if "NFAA" in columns and df["NFAA"] == "True": l.append('π€')
|
550 |
if "Likes" in columns and df["Likes"] > 0: l.append(f'π:{df["Likes"]}')
|
551 |
+
if df["T"] in ["model", "space", "dataset"]:
|
552 |
if "Trending" in columns and df["Trending"] > 0: l.append(f'trend:{df["Trending"]}')
|
553 |
+
if df["T"] in ["model", "dataset"]:
|
554 |
if "DLs" in columns and df["DLs"] > 0: l.append(f'DL:{df["DLs"]}')
|
555 |
if "Gated" in columns and df["Gated"] in ["manual", "auto"]: l.append(f'π:{df["Gated"]}')
|
556 |
+
if df["T"] == "model":
|
557 |
if "Status" in columns:
|
558 |
if df["Status"] == "warm": l.append(f'inference:π₯')
|
559 |
elif df["Status"] == "cold": l.append(f'inference:π§')
|
560 |
+
if df["T"] == "space":
|
561 |
if "Hardware" in columns and df["Hardware"] in SPACE_HARDWARES and df["Hardware"] != "cpu-basic": l.append(f'{df["Hardware"]}')
|
562 |
if "SDK" in columns: l.append(f'{df["SDK"]}')
|
563 |
if "Stage" in columns and df["Stage"] in SPACE_STAGES_EMOJI.keys(): l.append(f'{SPACE_STAGES_EMOJI[df["Stage"]]}')
|
|
|
567 |
def shorten_type(df: pd.DataFrame, shorten=False):
|
568 |
if shorten:
|
569 |
for k, v in TYPES_SHORT.items():
|
570 |
+
if df["T"] == k: return v
|
571 |
|
572 |
def to_emoji(df: pd.DataFrame, label: str, key: str, emoji: str):
|
573 |
if df[label] == key: return f'{df["Emoji"]}{emoji}' if df["Emoji"] else f' {emoji}'
|
|
|
582 |
|
583 |
def format_md_df(df: pd.DataFrame, verbose=False):
|
584 |
df["ID"] = df.apply(id_to_md, axis=1, verbose=verbose)
|
585 |
+
df["T"] = df.apply(shorten_type, axis=1, shorten=verbose)
|
586 |
return df
|
587 |
|
588 |
hide_labels = [l for l in labels if l in self.hide_labels or l not in self.get_show_labels()]
|
|
|
630 |
if key in SORT_PARAM_TO_ITEM.keys(): key = SORT_PARAM_TO_ITEM[key]
|
631 |
types = set()
|
632 |
for i in self.item_list:
|
633 |
+
if "T" in i.keys(): types.add(i["T"])
|
634 |
if "paper" in types: return
|
635 |
if key in ["DLs", "AllDLs"] and ("space" in types or "collection" in types): key = "Likes"
|
636 |
if not key in self.labels.get()[0]: key = "Likes"
|
|
|
646 |
df, labels, label_types = self.get()
|
647 |
widths = self.labels.get_widths()
|
648 |
if self.phone_mode:
|
649 |
+
widths["T"] = "10%"
|
650 |
widths["ID"] = "90%"
|
651 |
column_widths = [widths[l] for l in labels]
|
652 |
+
if self.phone_mode:
|
653 |
+
labels = None
|
654 |
return gr.update(type="pandas", value=df, headers=labels, datatype=label_types, column_widths=column_widths, wrap=True, show_label=False)
|
655 |
|
656 |
def get_gr_hide_labels(self):
|