Spaces:
Runtime error
Runtime error
import streamlit as st | |
import torch | |
from transformers import AutoTokenizer, AutoModel | |
# load the pre-trained model | |
model = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2') | |
# set the app title | |
st.title("Brazilian Portuguese Sentence Similarity Checker") | |
# get the input sentences from the user | |
sentence1 = st.text_input("Enter the first sentence:") | |
sentence2 = st.text_input("Enter the second sentence:") | |
# check if both sentences are not empty | |
if sentence1 and sentence2: | |
embedding_1= model.encode(sentence1, convert_to_tensor=True) | |
embedding_2 = model.encode(sentence2, convert_to_tensor=True) | |
similarity = util.pytorch_cos_sim(embedding_1, embedding_2) | |
st.write("Similarity score between the sentences:", similarity) |