Spaces:
Sleeping
Sleeping
jonathanjordan21
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
import re
|
3 |
import inspect
|
|
|
4 |
|
5 |
from sentence_transformers import SentenceTransformer
|
6 |
from sentence_transformers.util import cos_sim
|
@@ -86,7 +87,6 @@ codes = """001 - Pendaftaran Kendaraan
|
|
86 |
009 - Penangguhan atau Deklarasi Perubahan Penggunaan Kendaraan""".split("\n")
|
87 |
|
88 |
|
89 |
-
|
90 |
examples = [
|
91 |
{"code": "001", "examples": [
|
92 |
"Register a new vehicle",
|
@@ -305,7 +305,11 @@ model_id = model_ids[-1]
|
|
305 |
model = SentenceTransformer(model_id, trust_remote_code=True)
|
306 |
|
307 |
# codes_emb = model.encode([x[6:] for x in codes])
|
308 |
-
codes_emb = model.encode([x["examples"] for x in examples])#.mean(axis=1)
|
|
|
|
|
|
|
|
|
309 |
|
310 |
|
311 |
def censor_middle(number, num_to_hide=4):
|
@@ -586,7 +590,8 @@ def reload(chosen_model_id):
|
|
586 |
model = SentenceTransformer(chosen_model_id, trust_remote_code=True)
|
587 |
model_id = chosen_model_id
|
588 |
# codes_emb = model.encode([x[6:] for x in codes])
|
589 |
-
codes_emb = model.encode([x["examples"] for x in examples])#.mean(axis=1)
|
|
|
590 |
return f"Model {chosen_model_id} has been succesfully loaded!"
|
591 |
return f"Model {chosen_model_id} is ready!"
|
592 |
|
|
|
1 |
import gradio as gr
|
2 |
import re
|
3 |
import inspect
|
4 |
+
import numpy as np
|
5 |
|
6 |
from sentence_transformers import SentenceTransformer
|
7 |
from sentence_transformers.util import cos_sim
|
|
|
87 |
009 - Penangguhan atau Deklarasi Perubahan Penggunaan Kendaraan""".split("\n")
|
88 |
|
89 |
|
|
|
90 |
examples = [
|
91 |
{"code": "001", "examples": [
|
92 |
"Register a new vehicle",
|
|
|
305 |
model = SentenceTransformer(model_id, trust_remote_code=True)
|
306 |
|
307 |
# codes_emb = model.encode([x[6:] for x in codes])
|
308 |
+
# codes_emb = model.encode([x["examples"] for x in examples])#.mean(axis=1)
|
309 |
+
codes_emb = np.mean([model.encode(x["examples"]) for x in examples], axis=1)
|
310 |
+
# for x in examples:
|
311 |
+
# codes_emb.append(model.encode(x["examples"]))
|
312 |
+
# codes_emb = np.mean(codes_emb, axis=1)
|
313 |
|
314 |
|
315 |
def censor_middle(number, num_to_hide=4):
|
|
|
590 |
model = SentenceTransformer(chosen_model_id, trust_remote_code=True)
|
591 |
model_id = chosen_model_id
|
592 |
# codes_emb = model.encode([x[6:] for x in codes])
|
593 |
+
# codes_emb = model.encode([x["examples"] for x in examples])#.mean(axis=1)
|
594 |
+
codes_emb = np.mean([model.encode(x["examples"]) for x in examples], axis=1)
|
595 |
return f"Model {chosen_model_id} has been succesfully loaded!"
|
596 |
return f"Model {chosen_model_id} is ready!"
|
597 |
|