Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,11 @@
|
|
| 1 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
st.title("Text Similarity Checker")
|
| 4 |
|
|
@@ -6,4 +13,8 @@ text1 = st.text_input("Enter the first text:")
|
|
| 6 |
text2 = st.text_input("Enter the second text:")
|
| 7 |
|
| 8 |
if text1 and text2:
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from sentence_transformers import SentenceTransformer, util
|
| 3 |
+
|
| 4 |
+
@st.cache_resource
|
| 5 |
+
def load_model():
|
| 6 |
+
return SentenceTransformer('sentence-transformers/all-mpnet-base-v2')
|
| 7 |
+
|
| 8 |
+
model = load_model()
|
| 9 |
|
| 10 |
st.title("Text Similarity Checker")
|
| 11 |
|
|
|
|
| 13 |
text2 = st.text_input("Enter the second text:")
|
| 14 |
|
| 15 |
if text1 and text2:
|
| 16 |
+
# Calculate embeddings and similarity
|
| 17 |
+
embedding1 = model.encode(text1)
|
| 18 |
+
embedding2 = model.encode(text2)
|
| 19 |
+
similarity = util.cos_sim(embedding1, embedding2).item() * 100
|
| 20 |
+
st.write(f"**Similarity Score:** {similarity:.2f}%")
|