Update app.py
Browse files
app.py
CHANGED
@@ -23,7 +23,8 @@ def load_model():
|
|
23 |
model = AutoModelForSequenceClassification.from_pretrained(model_checkpoint, num_labels=2)
|
24 |
base_model = SentenceTransformer(base_model_checkpoint)
|
25 |
tokenizer = AutoTokenizer.from_pretrained(model_checkpoint, fast=True)
|
26 |
-
|
|
|
27 |
|
28 |
def sigmoid(x):
|
29 |
return 1 / (1 + np.exp(-x))
|
@@ -32,8 +33,7 @@ input_column, reference_column = st.columns(2)
|
|
32 |
input_column.write('# Fake News Detection AI')
|
33 |
|
34 |
with st.spinner("Loading Model..."):
|
35 |
-
model, base_model, tokenizer = load_model()
|
36 |
-
data = load_dataset(data_checkpoint, split="train")
|
37 |
|
38 |
user_input = input_column.text_input("Article url")
|
39 |
submit = input_column.button("submit")
|
@@ -71,16 +71,16 @@ if submit:
|
|
71 |
input_column.text(f"{int(result[prediction]*100)}% confidence")
|
72 |
input_column.progress(result[prediction])
|
73 |
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
|
|
23 |
model = AutoModelForSequenceClassification.from_pretrained(model_checkpoint, num_labels=2)
|
24 |
base_model = SentenceTransformer(base_model_checkpoint)
|
25 |
tokenizer = AutoTokenizer.from_pretrained(model_checkpoint, fast=True)
|
26 |
+
data = load_dataset(data_checkpoint, split="train")
|
27 |
+
return model, base_model, tokenizer, data
|
28 |
|
29 |
def sigmoid(x):
|
30 |
return 1 / (1 + np.exp(-x))
|
|
|
33 |
input_column.write('# Fake News Detection AI')
|
34 |
|
35 |
with st.spinner("Loading Model..."):
|
36 |
+
model, base_model, tokenizer, data = load_model()
|
|
|
37 |
|
38 |
user_input = input_column.text_input("Article url")
|
39 |
submit = input_column.button("submit")
|
|
|
71 |
input_column.text(f"{int(result[prediction]*100)}% confidence")
|
72 |
input_column.progress(result[prediction])
|
73 |
|
74 |
+
title_embeddings = base_model.encode(title)
|
75 |
+
similarity_score = cosine_similarity(
|
76 |
+
[title_embeddings],
|
77 |
+
data["embeddings"]
|
78 |
+
).flatten()
|
79 |
+
sorted = np.argsort(similarity_score)[::-1].tolist()
|
80 |
+
for i in sorted[:5]:
|
81 |
+
reference_column.write(f"""
|
82 |
+
<a href={data["url"][i]}><small>turnbackhoax.id</small></a>
|
83 |
+
<h5>{data["title"][i]}</h5>
|
84 |
+
""", unsafe_allow_html=True)
|
85 |
+
with reference_column.expander("read content"):
|
86 |
+
st.write(data["text"][i])
|