nouamanetazi HF staff commited on
Commit
d362bcf
β€’
1 Parent(s): 759959d

update hf_search

Browse files
Files changed (1) hide show
  1. st_utils.py +7 -6
st_utils.py CHANGED
@@ -1,10 +1,12 @@
1
  import json
2
  from huggingface_hub import HfApi, ModelFilter, DatasetFilter, ModelSearchArguments
3
  from pprint import pprint
4
- from hf_search import hf_search
5
  import streamlit as st
6
  import itertools
7
 
 
 
8
  @st.cache
9
  def hf_api(query, limit=5, filters={}):
10
  print("query", query)
@@ -31,7 +33,6 @@ def hf_api(query, limit=5, filters={}):
31
  count = len(hits)
32
  if len(hits) > limit:
33
  hits = hits[:limit]
34
- pprint(hits)
35
  return {"hits": hits, "count": count}
36
 
37
 
@@ -41,7 +42,7 @@ def semantic_search(query, limit=5, filters={}):
41
  print("filters", filters)
42
  print("limit", limit)
43
 
44
- hits = hf_search(query=query, method="retrieve & rerank", limit=limit, filters=filters)
45
  hits = [
46
  {
47
  "modelId": hit["modelId"],
@@ -62,13 +63,13 @@ def bm25_search(query, limit=5, filters={}):
62
  print("limit", limit)
63
 
64
  # TODO: filters
65
- hits = hf_search(query=query, method="bm25", limit=limit)
66
  hits = [
67
  {
68
  "modelId": hit["modelId"],
69
  "tags": hit["tags"],
70
- "downloads": hit["downloads"],
71
- "likes": hit["likes"],
72
  "readme": hit.get("readme", None),
73
  }
74
  for hit in hits
 
1
  import json
2
  from huggingface_hub import HfApi, ModelFilter, DatasetFilter, ModelSearchArguments
3
  from pprint import pprint
4
+ from hf_search import HFSearch
5
  import streamlit as st
6
  import itertools
7
 
8
+ hf_search = HFSearch(top_k=32)
9
+
10
  @st.cache
11
  def hf_api(query, limit=5, filters={}):
12
  print("query", query)
 
33
  count = len(hits)
34
  if len(hits) > limit:
35
  hits = hits[:limit]
 
36
  return {"hits": hits, "count": count}
37
 
38
 
 
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"],
 
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"],
70
  "tags": hit["tags"],
71
+ "downloads": int(hit["downloads"]),
72
+ "likes": int(hit["likes"]),
73
  "readme": hit.get("readme", None),
74
  }
75
  for hit in hits