auto-grader / app.py
Kuaaangwen's picture
Update app.py
fee5ced
raw
history blame
1.05 kB
import streamlit as st
from transformers import pipeline
from textblob import TextBlob
from sentence_transformers import SentenceTransformer
from sklearn.metrics.pairwise import cosine_similarity
model = SentenceTransformer('paraphrase-xlm-r-multilingual-v1')
sentences = []
# Streamlit interface
st.title("Sentence Similarity")
# Streamlit webpage elements
sentence_1 = st.text_input("Sentence 1 input")
sentence_2 = st.text_input("Sentence 2 input")
submit_button = st.button("submit")
if submit_button:
# Perform calculations
# Append input sentences to 'sentences' list
sentences.append(sentence_1)
sentences.append(sentence_2)
# Create embeddings for both sentences
sentence_embeddings = model.encode(sentences)
st.write('Similarity between {} and {} is {}'.format(sentence_1,
sentence_2,
cosine_similarity(sentence_embeddings[0].reshape(1, -1),
sentence_embeddings[1].reshape(1, -1))[0][0]))