JoBeer commited on
Commit
9d3184b
1 Parent(s): f59d886

Upload Sicherungskopie_Demo.txt

Browse files
Files changed (1) hide show
  1. Sicherungskopie_Demo.txt +59 -0
Sicherungskopie_Demo.txt ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import sentence_transformers
3
+ from sentence_transformers import SentenceTransformer
4
+ import torch
5
+ from sentence_transformers.util import semantic_search
6
+ import pandas as pd
7
+
8
+ model = SentenceTransformer('gart-labor/eng-distilBERT-se-eclass')
9
+
10
+
11
+ corpus = pd.read_json('corpus.jsonl', lines = True, encoding = 'utf-8')
12
+
13
+ def predict(name, description):
14
+ text = 'Description: '+ description + '; Name: ' + name
15
+ query_embedding = model.encode(text, convert_to_tensor=True)
16
+
17
+ corpus_embeddings = torch.Tensor(corpus["embeddings"])
18
+
19
+ output = sentence_transformers.util.semantic_search(query_embedding, corpus_embeddings, top_k = 5)
20
+
21
+ preferedName1 = corpus.iloc[output[0][0].get('corpus_id'),2]
22
+ definition1 = corpus.iloc[output[0][0].get('corpus_id'),1]
23
+ IRDI1 = corpus.iloc[output[0][0].get('corpus_id'),4]
24
+ score1 = output[0][0].get('score')
25
+
26
+ preferedName2 = corpus.iloc[output[0][1].get('corpus_id'),2]
27
+ definition2 = corpus.iloc[output[0][1].get('corpus_id'),1]
28
+ IRDI2 = corpus.iloc[output[0][1].get('corpus_id'),4]
29
+ score2 = output[0][1].get('score')
30
+
31
+ preferedName3 = corpus.iloc[output[0][2].get('corpus_id'),2]
32
+ definition3 = corpus.iloc[output[0][2].get('corpus_id'),1]
33
+ IRDI3 = corpus.iloc[output[0][2].get('corpus_id'),4]
34
+ score3 = output[0][2].get('score')
35
+
36
+ preferedName4 = corpus.iloc[output[0][3].get('corpus_id'),2]
37
+ definition4 = corpus.iloc[output[0][3].get('corpus_id'),1]
38
+ IRDI4 = corpus.iloc[output[0][3].get('corpus_id'),4]
39
+ score4 = output[0][3].get('score')
40
+
41
+ preferedName5 = corpus.iloc[output[0][4].get('corpus_id'),2]
42
+ definition5 = corpus.iloc[output[0][4].get('corpus_id'),1]
43
+ IRDI5 = corpus.iloc[output[0][4].get('corpus_id'),4]
44
+ score5 = output[0][4].get('score')
45
+
46
+ df = [[preferedName1, IRDI1, score1], [preferedName2, IRDI2, score2],[preferedName3, IRDI3, score3],[preferedName4, IRDI4, score4], [preferedName5, IRDI5, score5]]
47
+
48
+ return pd.DataFrame(df)
49
+
50
+ interface = gr.Interface(fn = predict,
51
+ inputs = [gr.Textbox(label="Name:", placeholder="Name of the Pump Property", lines=1), gr.Textbox(label="Description:", placeholder="Description of the Pump Property", lines=1)],
52
+ #outputs = [gr.Textbox(label = 'preferedName'),gr.Textbox(label = 'definition'), gr.Textbox(label = 'IDRI'),gr.Textbox(label = 'score')],
53
+ outputs = [gr.Dataframe(row_count = (5, "fixed"), col_count=(3, "fixed"), label="Predictions", headers=['ECLASS preferedName', 'ECLASS IRDI', 'simularity score'])],
54
+ examples = [['Device type', 'describing a set of common specific characteristics in products or goods'], ['Item type','the type of product, an item can be assigned to'],
55
+ ['Nominal power','power being consumed by or dissipated within an electric component as a variable'], ['Power consumption', 'power that is typically taken from the auxiliary power supply when the device is operating normally']],
56
+ #theme = 'huggingface',
57
+ title = 'ECLASS-Property-Search', description = "This is a semantic search algorithm that mapps unknown pump properties to the ECLASS standard.")
58
+
59
+ interface.launch()