Spaces:
Sleeping
Sleeping
Commit
•
b19a023
0
Parent(s):
Duplicate from justest/embeddings-api
Browse files- .gitattributes +35 -0
- .gitignore +2 -0
- README.md +14 -0
- app.py +8 -0
- init_data.py +39 -0
- model.py +7 -0
- requirements.txt +1 -0
- translated-content +1 -0
.gitattributes
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
__pycache__
|
2 |
+
/flagged
|
README.md
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Embeddings Api
|
3 |
+
emoji: 🏢
|
4 |
+
colorFrom: blue
|
5 |
+
colorTo: green
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.36.1
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
license: apache-2.0
|
11 |
+
duplicated_from: justest/embeddings-api
|
12 |
+
---
|
13 |
+
|
14 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import model
|
3 |
+
|
4 |
+
def encode(text):
|
5 |
+
return model.encode(text)
|
6 |
+
|
7 |
+
iface = gr.Interface(fn=encode, inputs="text", outputs="text")
|
8 |
+
iface.launch()
|
init_data.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from qdrant_client import QdrantClient
|
2 |
+
from qdrant_client.http.models import Distance, VectorParams
|
3 |
+
from qdrant_client.http.models import PointStruct
|
4 |
+
import tqdm
|
5 |
+
import glob
|
6 |
+
import model
|
7 |
+
import re
|
8 |
+
|
9 |
+
if __name__ == '__main__':
|
10 |
+
client = QdrantClient("127.0.0.1", port=6333)
|
11 |
+
collection_name = "mdn-docs"
|
12 |
+
client.recreate_collection(
|
13 |
+
collection_name=collection_name,
|
14 |
+
vectors_config=VectorParams(size=768, distance=Distance.COSINE),
|
15 |
+
)
|
16 |
+
|
17 |
+
count = 0
|
18 |
+
files = glob.glob("translated-content/files/zh-cn/**/*.md", recursive=True)
|
19 |
+
print(len(files))
|
20 |
+
for file in tqdm.tqdm(files):
|
21 |
+
count+=1
|
22 |
+
with open(file, 'r', encoding='utf-8') as f:
|
23 |
+
print('file', file)
|
24 |
+
text = f.read()
|
25 |
+
matchObj = re.match(r'\s*---[\n\r]+title:(((?!---).)+)', text, re.M|re.I)
|
26 |
+
if matchObj:
|
27 |
+
title = matchObj.group(1).strip()
|
28 |
+
else:
|
29 |
+
title = file
|
30 |
+
|
31 |
+
vector = model.encode(text)
|
32 |
+
client.upsert(
|
33 |
+
collection_name=collection_name,
|
34 |
+
wait=True,
|
35 |
+
points=[
|
36 |
+
PointStruct(id=count, vector=vector, payload={"title": title, "text": text }),
|
37 |
+
],
|
38 |
+
)
|
39 |
+
|
model.py
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from sentence_transformers import SentenceTransformer
|
2 |
+
model = SentenceTransformer('moka-ai/m3e-base')
|
3 |
+
# model = SentenceTransformer('nghuyong/ernie-3.0-base-zh')
|
4 |
+
|
5 |
+
def encode(text: str):
|
6 |
+
text = text.replace("\n", " ")
|
7 |
+
return model.encode([text], normalize_embeddings=True).tolist()[0]
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
sentence-transformers==2.2.2
|
translated-content
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
Subproject commit 79462bd3fd2533e3b71a117d1c98fafb8d4ca0e2
|