Spaces:
Runtime error
Runtime error
import gradio as gr | |
import sentence_transformers | |
from sentence_transformers import SentenceTransformer | |
import torch | |
from sentence_transformers.util import semantic_search | |
import os | |
import pandas as pd | |
model = SentenceTransformer('JoBeer/all-mpnet-base-v2-eclass') | |
#corpus = pd.read_excel('corpus.xlsx') | |
os.chdir() | |
corpus = pd.read_json('corpus.jsonl', lines = True, encoding = 'utf-8') | |
def predict(name, description): | |
text = 'Description: '+ description + '; Name: ' + name | |
query_embedding = model.encode(text, convert_to_tensor=True) | |
corpus_embeddings = torch.Tensor(corpus["embeddings"]) | |
output = sentence_transformers.util.semantic_search(query_embedding, corpus_embeddings, top_k = 5) | |
preferedName1 = corpus.iloc[output[0][0].get('corpus_id'),2] | |
definition1 = corpus.iloc[output[0][0].get('corpus_id'),1] | |
IRDI1 = corpus.iloc[output[0][0].get('corpus_id'),4] | |
score1 = output[0][0].get('score') | |
return preferedName1, definition1, IRDI1, score1 | |
interface = gr.Interface(fn = predict, inputs = [gr.Textbox(label="Name:", placeholder="z.B. GTIN", lines=1), gr.Textbox(label="Description:", placeholder="z.B. Globel Trade Item Number", lines=1)], | |
outputs = [gr.Textbox(label = 'preferedName'),gr.Textbox(label = 'definition'), gr.Textbox(label = 'IDRI'),gr.Textbox(label = 'score')], | |
#examples=[['GTIN', 'Globel Trade Item Number']], theme = 'huggingface', | |
title = 'ECLASS-Property-Search') | |
interface.launch() |