Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from sentence_transforms import SentenceTransformer, util
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
mopdel = SentenceTransformer("all-MiniLM-L6-v2")
|
| 5 |
+
|
| 6 |
+
def calcular_similaridade(frase1, frase2):
|
| 7 |
+
emb1 = model.encode(frase1, convert_to_tensor=True)
|
| 8 |
+
emb2 = model.encode(frase2, convert_to_tensor=True)
|
| 9 |
+
score = util.cos_sim(emb1, emb2).item()
|
| 10 |
+
return round(score,3)
|
| 11 |
+
|
| 12 |
+
iface = gr.Interface(
|
| 13 |
+
fn=calcular_similaridade,
|
| 14 |
+
inputs=["text", "text",]
|
| 15 |
+
outputs="number,"
|
| 16 |
+
title="Similaridade Semântica",
|
| 17 |
+
description="Digite duas frases e veja o quão sematicamente parecidas elas são."
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
iface.launch()
|