antagonico commited on
Commit
a8efbc5
1 Parent(s): 314e98e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -3
app.py CHANGED
@@ -1,7 +1,31 @@
1
  import gradio as gr
 
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  iface.launch()
 
1
  import gradio as gr
2
+ from sentence_transformers import SentenceTransformer
3
+ from sklearn.metrics.pairwise import cosine_similarity
4
+ import numpy as np
5
 
6
+ # Carga el modelo
7
+ model = SentenceTransformer('Maite89/Roberta_finetuning_semantic_similarity_stsb_multi_mt')
8
 
9
+ # Funci贸n para obtener embeddings del modelo
10
+ def get_embeddings(sentences):
11
+ embeddings = model.encode(sentences, show_progress_bar=False)
12
+ return np.array(embeddings)
13
+
14
+ # Funci贸n para comparar las sentencias
15
+ def compare(source_sentence, compare_sentence):
16
+ # Calcula la similitud
17
+ embeddings = get_embeddings([source_sentence, compare_sentence])
18
+ similarity = float(cosine_similarity(embeddings[0].reshape(1, -1), embeddings[1].reshape(1, -1))[0][0]) # Convert the numpy.float32 to Python float
19
+
20
+ return similarity
21
+
22
+ # Define las interfaces de entrada y salida de Gradio
23
+ iface = gr.Interface(
24
+ fn=compare,
25
+ inputs=["text", "text"],
26
+ outputs="number",
27
+ live=True
28
+ )
29
+
30
+ # Inicia la interfaz de Gradio
31
  iface.launch()