Spaces:
Runtime error
Runtime error
File size: 1,098 Bytes
ccadf3d 0112269 ccadf3d dd00e4b ccadf3d 6e5530c 8f12b5e ccadf3d 8f12b5e ccadf3d 693cebb 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 28 |
from sentence_transformers import SentenceTransformer, util
import gradio as gr
#Initializing the bert embedding model
bert_model = SentenceTransformer('all-MiniLM-L6-v2')
#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_similarities = util.pytorch_cos_sim(headline_embedding_1, headline_embedding_2)
similarities_percent = bert_similarities * 100
if bert_similarities > 0.7:
result = f"similar: {similarities_percent[0][0]}"
else:
result = f"not similar: {similarities_percent[0][0]}"
return result
demo = gr.Interface(similar_headline, inputs=[gr.Textbox(label="Input the first headline here"),
gr.Textbox(label="Input the second headline here")],
outputs = "text",
title="News Headline Similarities")
#Launching the gradio app
if __name__ == '__main__':
demo.launch(debug=True) |