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