Spaces:
Running
Running
Commit
•
48bcb8a
1
Parent(s):
03bc0ff
add sorting
Browse files- app.py +9 -4
- requirements.txt +2 -1
- st_utils.py +13 -7
app.py
CHANGED
@@ -19,6 +19,11 @@ search_backend = st.sidebar.selectbox(
|
|
19 |
format_func=lambda x: {"hfapi": "Keyword search", "bm25": "BM25 search", "semantic": "Semantic Search"}[x],
|
20 |
)
|
21 |
limit_results = int(st.sidebar.number_input("Limit results", min_value=0, value=10))
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
st.sidebar.markdown("# Filters")
|
24 |
args = ModelSearchArguments()
|
@@ -44,11 +49,11 @@ if search_query != "":
|
|
44 |
"task": task,
|
45 |
}
|
46 |
if search_backend == "hfapi":
|
47 |
-
res = hf_api(search_query, limit_results, filters)
|
48 |
elif search_backend == "semantic":
|
49 |
-
res = semantic_search(search_query, limit_results, filters)
|
50 |
elif search_backend == "bm25":
|
51 |
-
res = bm25_search(search_query, limit_results, filters)
|
52 |
hit_list, hits_count = res["hits"], res["count"]
|
53 |
hit_list = [
|
54 |
{
|
@@ -79,7 +84,7 @@ if search_query != "":
|
|
79 |
col3.metric("N° likes", numerize(hit["likes"]) if not math.isnan(hit["likes"]) else "N/A")
|
80 |
st.button(
|
81 |
f"View model on 🤗",
|
82 |
-
on_click=lambda hit=hit: webbrowser.open(f"https://huggingface.co/{hit['modelId']}"),
|
83 |
key=f"{i}-{hit['modelId']}",
|
84 |
)
|
85 |
st.write(f"**Tags:** {' • '.join(hit['tags'])}")
|
|
|
19 |
format_func=lambda x: {"hfapi": "Keyword search", "bm25": "BM25 search", "semantic": "Semantic Search"}[x],
|
20 |
)
|
21 |
limit_results = int(st.sidebar.number_input("Limit results", min_value=0, value=10))
|
22 |
+
sort_by = st.sidebar.selectbox(
|
23 |
+
"Sort by",
|
24 |
+
[None, "downloads", "likes", "lastModified"],
|
25 |
+
format_func=lambda x: {None: "Relevance", "downloads": "Most downloads", "likes": "Most likes", "lastModified": "Recently updated"}[x],
|
26 |
+
)
|
27 |
|
28 |
st.sidebar.markdown("# Filters")
|
29 |
args = ModelSearchArguments()
|
|
|
49 |
"task": task,
|
50 |
}
|
51 |
if search_backend == "hfapi":
|
52 |
+
res = hf_api(search_query, limit_results, sort_by, filters)
|
53 |
elif search_backend == "semantic":
|
54 |
+
res = semantic_search(search_query, limit_results, sort_by, filters)
|
55 |
elif search_backend == "bm25":
|
56 |
+
res = bm25_search(search_query, limit_results, sort_by, filters)
|
57 |
hit_list, hits_count = res["hits"], res["count"]
|
58 |
hit_list = [
|
59 |
{
|
|
|
84 |
col3.metric("N° likes", numerize(hit["likes"]) if not math.isnan(hit["likes"]) else "N/A")
|
85 |
st.button(
|
86 |
f"View model on 🤗",
|
87 |
+
on_click=lambda hit=hit: webbrowser.open(f"https://huggingface.co/{hit['modelId']}", new=2),
|
88 |
key=f"{i}-{hit['modelId']}",
|
89 |
)
|
90 |
st.write(f"**Tags:** {' • '.join(hit['tags'])}")
|
requirements.txt
CHANGED
@@ -2,4 +2,5 @@ pandas
|
|
2 |
streamlit
|
3 |
huggingface_hub
|
4 |
numerize
|
5 |
-
|
|
|
|
2 |
streamlit
|
3 |
huggingface_hub
|
4 |
numerize
|
5 |
+
pbr
|
6 |
+
git+https://github.com/NouamaneTazi/hf_search@0.4
|
st_utils.py
CHANGED
@@ -5,20 +5,24 @@ from hf_search import HFSearch
|
|
5 |
import streamlit as st
|
6 |
import itertools
|
7 |
|
8 |
-
|
|
|
|
|
|
|
9 |
|
10 |
@st.cache
|
11 |
-
def hf_api(query, limit=5, filters={}):
|
12 |
print("query", query)
|
13 |
print("filters", filters)
|
14 |
print("limit", limit)
|
|
|
15 |
|
16 |
api = HfApi()
|
17 |
filt = ModelFilter(
|
18 |
task=filters["task"],
|
19 |
library=filters["library"],
|
20 |
)
|
21 |
-
models = api.list_models(search=query, filter=filt, limit=limit, full=True)
|
22 |
hits = []
|
23 |
for model in models:
|
24 |
model = model.__dict__
|
@@ -37,12 +41,13 @@ def hf_api(query, limit=5, filters={}):
|
|
37 |
|
38 |
|
39 |
@st.cache
|
40 |
-
def semantic_search(query, limit=5, filters={}):
|
41 |
print("query", query)
|
42 |
print("filters", filters)
|
43 |
print("limit", limit)
|
|
|
44 |
|
45 |
-
hits = hf_search.search(query=query, method="retrieve & rerank", limit=limit, filters=filters)
|
46 |
hits = [
|
47 |
{
|
48 |
"modelId": hit["modelId"],
|
@@ -57,13 +62,14 @@ def semantic_search(query, limit=5, filters={}):
|
|
57 |
|
58 |
|
59 |
@st.cache
|
60 |
-
def bm25_search(query, limit=5, filters={}):
|
61 |
print("query", query)
|
62 |
print("filters", filters)
|
63 |
print("limit", limit)
|
|
|
64 |
|
65 |
# TODO: filters
|
66 |
-
hits = hf_search.search(query=query, method="bm25", limit=limit, filters=filters)
|
67 |
hits = [
|
68 |
{
|
69 |
"modelId": hit["modelId"],
|
|
|
5 |
import streamlit as st
|
6 |
import itertools
|
7 |
|
8 |
+
from pbr.version import VersionInfo
|
9 |
+
print("hf_search version:", VersionInfo('hf_search').version_string())
|
10 |
+
|
11 |
+
hf_search = HFSearch(top_k=1000)
|
12 |
|
13 |
@st.cache
|
14 |
+
def hf_api(query, limit=5, sort=None, filters={}):
|
15 |
print("query", query)
|
16 |
print("filters", filters)
|
17 |
print("limit", limit)
|
18 |
+
print("sort", sort)
|
19 |
|
20 |
api = HfApi()
|
21 |
filt = ModelFilter(
|
22 |
task=filters["task"],
|
23 |
library=filters["library"],
|
24 |
)
|
25 |
+
models = api.list_models(search=query, filter=filt, limit=limit, sort=sort, full=True)
|
26 |
hits = []
|
27 |
for model in models:
|
28 |
model = model.__dict__
|
|
|
41 |
|
42 |
|
43 |
@st.cache
|
44 |
+
def semantic_search(query, limit=5, sort=None, filters={}):
|
45 |
print("query", query)
|
46 |
print("filters", filters)
|
47 |
print("limit", limit)
|
48 |
+
print("sort", sort)
|
49 |
|
50 |
+
hits = hf_search.search(query=query, method="retrieve & rerank", limit=limit, sort=sort, filters=filters)
|
51 |
hits = [
|
52 |
{
|
53 |
"modelId": hit["modelId"],
|
|
|
62 |
|
63 |
|
64 |
@st.cache
|
65 |
+
def bm25_search(query, limit=5, sort=None, filters={}):
|
66 |
print("query", query)
|
67 |
print("filters", filters)
|
68 |
print("limit", limit)
|
69 |
+
print("sort", sort)
|
70 |
|
71 |
# TODO: filters
|
72 |
+
hits = hf_search.search(query=query, method="bm25", limit=limit, sort=sort, filters=filters)
|
73 |
hits = [
|
74 |
{
|
75 |
"modelId": hit["modelId"],
|