Adam-Al-Rahman
commited on
Commit
β’
c1810f7
1
Parent(s):
5003a38
add: form
Browse files
README.md
CHANGED
@@ -20,7 +20,6 @@ It is fake news detection based on the following models trained on datasets
|
|
20 |
We have used following datasets to create our own datasets and train models.
|
21 |
|
22 |
- [Kaggle: Fake news detection dataset english](https://www.kaggle.com/datasets/sadikaljarif/fake-news-detection-dataset-english)
|
23 |
-
- [Kaggle: Liar twitter](https://www.kaggle.com/datasets/muhammadimran112233/liar-twitter-dataset)
|
24 |
- [Kaggle: Liar Preprocessed](https://www.kaggle.com/datasets/khandalaryan/liar-preprocessed-dataset)
|
25 |
- [Kaggle: Stocknews](https://www.kaggle.com/datasets/aaron7sun/stocknews)
|
26 |
|
|
|
20 |
We have used following datasets to create our own datasets and train models.
|
21 |
|
22 |
- [Kaggle: Fake news detection dataset english](https://www.kaggle.com/datasets/sadikaljarif/fake-news-detection-dataset-english)
|
|
|
23 |
- [Kaggle: Liar Preprocessed](https://www.kaggle.com/datasets/khandalaryan/liar-preprocessed-dataset)
|
24 |
- [Kaggle: Stocknews](https://www.kaggle.com/datasets/aaron7sun/stocknews)
|
25 |
|
app.py
CHANGED
@@ -10,23 +10,22 @@ st.set_page_config(layout="centered", page_title="X_G85 Fake News", page_icon="
|
|
10 |
############ CREATE THE LOGO AND HEADING ############
|
11 |
|
12 |
# We create a set of columns to display the logo and the heading next to each other.
|
13 |
-
|
14 |
c1, c2 = st.columns([0.32, 2])
|
15 |
|
16 |
# The snowflake logo will be displayed in the first column, on the left.
|
17 |
-
|
18 |
with c1:
|
19 |
st.caption("")
|
20 |
st.title("π")
|
21 |
|
22 |
# The heading will be on the right.
|
23 |
-
|
24 |
with c2:
|
25 |
|
26 |
st.caption("")
|
27 |
st.title("X_G85 Fake News")
|
28 |
|
29 |
# We need to set up session state via st.session_state so that app interactions don't reset the app.
|
|
|
|
|
30 |
|
31 |
############ SIDEBAR CONTENT ############
|
32 |
|
@@ -40,6 +39,9 @@ SELECTED_MODEL = st.sidebar.selectbox(
|
|
40 |
("Bert", "Roberta", "Lstm")
|
41 |
)
|
42 |
|
|
|
|
|
|
|
43 |
MODEL_INFO = {
|
44 |
"Bert": """
|
45 |
#### [BERT base model (uncased)](https://huggingface.co/google-bert/bert-base-uncased)
|
@@ -83,9 +85,8 @@ with InfoTab:
|
|
83 |
st.subheader("Datasets")
|
84 |
st.markdown(
|
85 |
"""
|
86 |
-
We have used following datasets to create our own datasets and train models.
|
87 |
- [Kaggle: Fake news detection dataset english](https://www.kaggle.com/datasets/sadikaljarif/fake-news-detection-dataset-english)
|
88 |
-
- [Kaggle: Liar twitter](https://www.kaggle.com/datasets/muhammadimran112233/liar-twitter-dataset)
|
89 |
- [Kaggle: Liar Preprocessed](https://www.kaggle.com/datasets/khandalaryan/liar-preprocessed-dataset)
|
90 |
- [Kaggle: Stocknews](https://www.kaggle.com/datasets/aaron7sun/stocknews)
|
91 |
"""
|
@@ -110,7 +111,7 @@ def MODEL_RESULT(model: str, news: str) -> str | None:
|
|
110 |
result = classifier(news)
|
111 |
|
112 |
if result[0]["label"] == "LABEL_1":
|
113 |
-
return "
|
114 |
else:
|
115 |
return "FAKE NEWS"
|
116 |
|
@@ -133,25 +134,35 @@ with MainTab:
|
|
133 |
container = st.container(border=True)
|
134 |
container.write(f"Selected model: {SELECTED_MODEL}")
|
135 |
|
|
|
|
|
136 |
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
key="news")
|
143 |
|
144 |
-
|
145 |
-
result = MODEL_RESULT(model=SELECTED_MODEL if SELECTED_MODEL else "Bert", news=news)
|
146 |
-
result_container = st.container(border=True)
|
147 |
-
if news:
|
148 |
-
if result:
|
149 |
-
result_container.markdown(f"Result: {result}")
|
150 |
-
else:
|
151 |
-
result_container.markdown("ML MODEL ERROR")
|
152 |
|
|
|
|
|
153 |
|
|
|
|
|
|
|
|
|
154 |
|
|
|
|
|
|
|
155 |
|
|
|
|
|
|
|
156 |
|
|
|
|
|
|
|
|
|
157 |
|
|
|
10 |
############ CREATE THE LOGO AND HEADING ############
|
11 |
|
12 |
# We create a set of columns to display the logo and the heading next to each other.
|
|
|
13 |
c1, c2 = st.columns([0.32, 2])
|
14 |
|
15 |
# The snowflake logo will be displayed in the first column, on the left.
|
|
|
16 |
with c1:
|
17 |
st.caption("")
|
18 |
st.title("π")
|
19 |
|
20 |
# The heading will be on the right.
|
|
|
21 |
with c2:
|
22 |
|
23 |
st.caption("")
|
24 |
st.title("X_G85 Fake News")
|
25 |
|
26 |
# We need to set up session state via st.session_state so that app interactions don't reset the app.
|
27 |
+
if "valid_inputs_received" not in st.session_state:
|
28 |
+
st.session_state["valid_inputs_received"] = False
|
29 |
|
30 |
############ SIDEBAR CONTENT ############
|
31 |
|
|
|
39 |
("Bert", "Roberta", "Lstm")
|
40 |
)
|
41 |
|
42 |
+
if SELECTED_MODEL:
|
43 |
+
st.session_state.valid_inputs_received = False
|
44 |
+
|
45 |
MODEL_INFO = {
|
46 |
"Bert": """
|
47 |
#### [BERT base model (uncased)](https://huggingface.co/google-bert/bert-base-uncased)
|
|
|
85 |
st.subheader("Datasets")
|
86 |
st.markdown(
|
87 |
"""
|
88 |
+
We have used the following datasets to create our own datasets and train models.
|
89 |
- [Kaggle: Fake news detection dataset english](https://www.kaggle.com/datasets/sadikaljarif/fake-news-detection-dataset-english)
|
|
|
90 |
- [Kaggle: Liar Preprocessed](https://www.kaggle.com/datasets/khandalaryan/liar-preprocessed-dataset)
|
91 |
- [Kaggle: Stocknews](https://www.kaggle.com/datasets/aaron7sun/stocknews)
|
92 |
"""
|
|
|
111 |
result = classifier(news)
|
112 |
|
113 |
if result[0]["label"] == "LABEL_1":
|
114 |
+
return "REAL NEWS"
|
115 |
else:
|
116 |
return "FAKE NEWS"
|
117 |
|
|
|
134 |
container = st.container(border=True)
|
135 |
container.write(f"Selected model: {SELECTED_MODEL}")
|
136 |
|
137 |
+
with st.form(key="form"):
|
138 |
+
pre_defined_news = "Indonesian police have recaptured a U.S. citizen who escaped a week ago from an overcrowded prison on the holiday island of Bali, the jail's second breakout of foreign inmates this year. Cristian Beasley from California was rearrested on Sunday, Badung Police Chief Yudith Satria Hananta said, without providing further details. Beasley was a suspect in crimes related to narcotics but had not been sentenced when he escaped from Kerobokan prison in Bali last week. The 32-year-old is believed to have cut through bars in the ceiling of his cell before scaling a perimeter wall of the prison in an area being refurbished. The Kerobokan prison, about 10 km (six miles) from the main tourist beaches in the Kuta area, often holds foreigners facing drug-related charges. Representatives of Beasley could not immediately be reached for comment. In June, an Australian, a Bulgarian, an Indian, and a Malaysian tunneled to freedom about 12 meters (13 yards) under Kerobokan prison s walls. The Indian and the Bulgarian were caught soon after in neighboring East Timor, but Australian Shaun Edward Davidson and Malaysian Tee Kok King remain at large. Davidson has taunted authorities by saying he was enjoying life in various parts of the world, in purported posts on Facebook. Kerobokan has housed several well-known foreign drug convicts, including Australian Schappelle Corby, whose 12-1/2-year sentence for marijuana smuggling got huge media attention."
|
139 |
|
140 |
+
news = st.text_area("Enter news to classify",
|
141 |
+
pre_defined_news,
|
142 |
+
height=200,
|
143 |
+
help="Please provide the news that you need to verify for its truthfulness.",
|
144 |
+
key="news")
|
|
|
145 |
|
146 |
+
submit_button = st.form_submit_button(label="Submit")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
147 |
|
148 |
+
if not news and not submit_button and not st.session_state.valid_inputs_received:
|
149 |
+
st.stop()
|
150 |
|
151 |
+
elif submit_button and not news:
|
152 |
+
st.warning("π There is no news to classify")
|
153 |
+
st.session_state.valid_inputs_received = False
|
154 |
+
st.stop()
|
155 |
|
156 |
+
elif submit_button or st.session_state.valid_inputs_received:
|
157 |
+
if submit_button:
|
158 |
+
st.session_state.valid_inputs_received = True
|
159 |
|
160 |
+
# Default Model: Bert
|
161 |
+
MODEL = SELECTED_MODEL if SELECTED_MODEL else "Bert"
|
162 |
+
result = MODEL_RESULT(model= MODEL, news=news)
|
163 |
|
164 |
+
if result:
|
165 |
+
st.success(f"Result: {result}")
|
166 |
+
else:
|
167 |
+
st.error(f"{MODEL} model error")
|
168 |
|