Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
import sentence_transformers
|
3 |
from sentence_transformers import SentenceTransformer
|
|
|
4 |
|
5 |
import pandas as pd
|
6 |
|
@@ -8,12 +9,24 @@ model = SentenceTransformer('JoBeer/all-mpnet-base-v2-eclass')
|
|
8 |
|
9 |
corpus = pd.read_excel('corpus.xlsx')
|
10 |
|
11 |
-
def predict(
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
-
interface = gr.Interface(fn = predict, inputs = gr.Textbox(label="
|
16 |
-
outputs = '
|
17 |
title = 'ECLASS-Property-Search')
|
18 |
|
19 |
interface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import sentence_transformers
|
3 |
from sentence_transformers import SentenceTransformer
|
4 |
+
from sentence_transformers.util import semantic_search
|
5 |
|
6 |
import pandas as pd
|
7 |
|
|
|
9 |
|
10 |
corpus = pd.read_excel('corpus.xlsx')
|
11 |
|
12 |
+
def predict(name, description):
|
13 |
+
text = 'Description: '+ description + '; Name: ' + name
|
14 |
+
query_embedding = model.encode(text, convert_to_tensor=True)
|
15 |
+
|
16 |
+
corpus_embeddings = torch.FloatTensor(corpus["embeddings"])
|
17 |
+
|
18 |
+
output = sentence_transformers.util.semantic_search(query_embedding, corpus_embeddings, top_k = 5)
|
19 |
+
|
20 |
+
preferedName1 = corpus.iloc[output[0][0].get('corpus_id'),2]
|
21 |
+
definition1 = corpus.iloc[output[0][0].get('corpus_id'),1]
|
22 |
+
IRDI1 = corpus.iloc[output[0][0].get('corpus_id'),4]
|
23 |
+
score1 = output[0][0].get('score')
|
24 |
+
|
25 |
+
|
26 |
+
return preferedName1, definition1, IRDI1, score1
|
27 |
|
28 |
+
interface = gr.Interface(fn = predict, inputs = [gr.Textbox(label="Description:", placeholder="z.B. Globel Trade Item Number", lines=1), gr.Textbox(label="Name:", placeholder="z.B. GTIN", lines=1)],
|
29 |
+
outputs = [gr.Textbox(label = 'preferedName'),gr.Textbox(label = 'definition'), gr.Textbox(label = 'IDRI'),gr.Textbox(label = 'score')]
|
30 |
title = 'ECLASS-Property-Search')
|
31 |
|
32 |
interface.launch()
|