Spaces:
Sleeping
Sleeping
Download app.py from DanielSilvaRJ/AulaEmb2: direct link, hf CLI and curl.
- Browser
- Download file 604 Bytes
-
https://huggingface.co/spaces/DanielSilvaRJ/AulaEmb2/resolve/main/app.py
- Command line
-
hf download hf://spaces/DanielSilvaRJ/AulaEmb2/app.py
-
curl -L -o app.py https://huggingface.co/spaces/DanielSilvaRJ/AulaEmb2/resolve/main/app.py
604 Bytes
| from sentence_transformers import SentenceTransformer, util | |
| import gradio as gr | |
| model = SentenceTransformer("all-MiniLM-L6-v2") | |
| def calcular_similaridade(frase1, frase2): | |
| emb1 = model.encode(frase1, convert_to_tensor=True) | |
| emb2 = model.encode(frase2, convert_to_tensor=True) | |
| score = util.cos_sim(emb1, emb2).item() | |
| return round(score, 3) | |
| iface = gr.Interface( | |
| fn=calcular_similaridade, | |
| inputs=["text", "text"], | |
| outputs="number", | |
| title="Similaridade Semântica", | |
| description="Digite duas frases e veja o quão semanticamente parecidas elas são." | |
| ) | |
| iface.launch() | |