Spaces:
Runtime error
Runtime error
Commit
·
d341f84
1
Parent(s):
a8e0066
Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,17 @@
|
|
1 |
import gradio as gr
|
2 |
from sentence_transformers import SentenceTransformer, util
|
3 |
-
|
4 |
model = None
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
def semantic(company_1, company_2):
|
6 |
global model
|
7 |
# Single list of sentences
|
8 |
-
sentences = [company_1, company_2]
|
9 |
if model is None:
|
10 |
model = SentenceTransformer('all-mpnet-base-v2')
|
11 |
#Compute embeddings
|
|
|
1 |
import gradio as gr
|
2 |
from sentence_transformers import SentenceTransformer, util
|
3 |
+
import string
|
4 |
model = None
|
5 |
+
def prepare(text):
|
6 |
+
text = text.translate(str.maketrans('', '', string.punctuation + '”“'))
|
7 |
+
pattern = r"\b(?=[MDCLXVIΙ])M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})([IΙ]X|[IΙ]V|V?[IΙ]{0,3})\b\.?"
|
8 |
+
text = re.sub(pattern, '', text)
|
9 |
+
return text.upper()
|
10 |
+
|
11 |
def semantic(company_1, company_2):
|
12 |
global model
|
13 |
# Single list of sentences
|
14 |
+
sentences = [prepare(company_1), prepare(company_2)]
|
15 |
if model is None:
|
16 |
model = SentenceTransformer('all-mpnet-base-v2')
|
17 |
#Compute embeddings
|