saurabhg2083 commited on
Commit
bcfecb7
1 Parent(s): c4b45e6
Files changed (1) hide show
  1. app.py +23 -0
app.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from sentence_transformers import SentenceTransformer, util
3
+
4
+ # Load the pre-trained SentenceTransformer model
5
+ model = SentenceTransformer('paraphrase-distilroberta-base-v2')
6
+
7
+ def compute_similarity(para1, para2):
8
+ embedding1 = model.encode(para1, convert_to_tensor=True)
9
+ embedding2 = model.encode(para2, convert_to_tensor=True)
10
+ cosine_sim = util.pytorch_cos_sim(embedding1, embedding2)
11
+ return cosine_sim.item()
12
+
13
+ st.title("Text Similarity Calculator")
14
+
15
+ text1 = st.text_area("Enter Text 1")
16
+ text2 = st.text_area("Enter Text 2")
17
+
18
+ if st.button("Calculate Similarity"):
19
+ if text1 and text2:
20
+ similarity_score = compute_similarity(text1, text2)
21
+ st.success(f"Similarity Score: {similarity_score:.4f}")
22
+ else:
23
+ st.warning("Please enter text in both fields.")