Spaces:
Running
Running
Commit
β’
6fd70a0
1
Parent(s):
dc1b8a3
add hf_search
Browse files- .gitattributes +1 -0
- requirements.txt +2 -1
- server/api.py +12 -11
.gitattributes
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
requirements.txt
CHANGED
@@ -2,4 +2,5 @@ altair
|
|
2 |
pandas
|
3 |
streamlit
|
4 |
huggingface_hub
|
5 |
-
numerize
|
|
|
|
2 |
pandas
|
3 |
streamlit
|
4 |
huggingface_hub
|
5 |
+
numerize
|
6 |
+
git+https://github.com/NouamaneTazi/hf_search hf_search
|
server/api.py
CHANGED
@@ -2,6 +2,7 @@ from flask import Flask, request
|
|
2 |
import json
|
3 |
from huggingface_hub import HfApi, ModelFilter, DatasetFilter, ModelSearchArguments
|
4 |
from pprint import pprint
|
|
|
5 |
|
6 |
app = Flask(__name__)
|
7 |
|
@@ -27,10 +28,10 @@ def hf_api():
|
|
27 |
library=filters["library"],
|
28 |
)
|
29 |
models = api.list_models(search=query, filter=filt, limit=limit, full=True)
|
30 |
-
|
31 |
for model in models:
|
32 |
model = model.__dict__
|
33 |
-
|
34 |
{
|
35 |
"modelId": model.get("modelId"),
|
36 |
"tags": model.get("tags"),
|
@@ -38,11 +39,11 @@ def hf_api():
|
|
38 |
"likes": model.get("likes"),
|
39 |
}
|
40 |
)
|
41 |
-
count = len(
|
42 |
-
if len(
|
43 |
-
|
44 |
-
pprint(
|
45 |
-
return json.dumps({"value":
|
46 |
|
47 |
|
48 |
@app.route("/custom/search", methods=["POST"])
|
@@ -55,10 +56,10 @@ def main():
|
|
55 |
print("filters", filters)
|
56 |
print("limit", limit)
|
57 |
|
58 |
-
#
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
|
63 |
|
64 |
if __name__ == "__main__":
|
|
|
2 |
import json
|
3 |
from huggingface_hub import HfApi, ModelFilter, DatasetFilter, ModelSearchArguments
|
4 |
from pprint import pprint
|
5 |
+
from hf_search import hf_search
|
6 |
|
7 |
app = Flask(__name__)
|
8 |
|
|
|
28 |
library=filters["library"],
|
29 |
)
|
30 |
models = api.list_models(search=query, filter=filt, limit=limit, full=True)
|
31 |
+
hits = []
|
32 |
for model in models:
|
33 |
model = model.__dict__
|
34 |
+
hits.append(
|
35 |
{
|
36 |
"modelId": model.get("modelId"),
|
37 |
"tags": model.get("tags"),
|
|
|
39 |
"likes": model.get("likes"),
|
40 |
}
|
41 |
)
|
42 |
+
count = len(hits)
|
43 |
+
if len(hits) > limit:
|
44 |
+
hits = hits[:limit]
|
45 |
+
pprint(hits)
|
46 |
+
return json.dumps({"value": hits, "count": count})
|
47 |
|
48 |
|
49 |
@app.route("/custom/search", methods=["POST"])
|
|
|
56 |
print("filters", filters)
|
57 |
print("limit", limit)
|
58 |
|
59 |
+
# TODO: filters
|
60 |
+
hits = hf_search(query=query, method="retrieve & rerank", limit=limit)
|
61 |
+
|
62 |
+
return json.dumps({"value": hits, "count": len(hits)})
|
63 |
|
64 |
|
65 |
if __name__ == "__main__":
|