abdulmatinomotoso commited on
Commit
ccadf3d
1 Parent(s): 0618a51

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -0
app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sentence_transformers import SentenceTransformer, util
2
+ import gradio as gr
3
+
4
+ #Initializing the bert embedding model
5
+ bert_model = SentenceTransformer('valurank/headline_similarities')
6
+
7
+ #Defining a function to check for the similarities of the two headlines
8
+ def similar_headline(headline_1, headline_2):
9
+ headline_embedding_1 = bert_model.encode(headline_1)
10
+ headline_embedding_2 = bert_model.encode(headline_2)
11
+
12
+ bert_similarites = util.pytorch_cos_sim(headline_embedding_1, headline_embedding_2)
13
+
14
+ if bert_similarites > 0.6:
15
+ result = "similar"
16
+ else:
17
+ result = "not similar"
18
+ return result
19
+
20
+ demo = gr.Interface(similar_headline, inputs=[gr.inputs.Textbox(label="Input the first headline here"),
21
+ gr.inputs.Textbox(label="Input the second headline here")],
22
+ outputs = "text",
23
+ title="News Headline Similarities")
24
+
25
+ #Launching the gradio app
26
+ if __name__ == '__main__':
27
+ demo.launch(debug=True)