Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -14,9 +14,6 @@ fake_news_pipeline = pipeline("text-classification", model="mrm8488/bert-tiny-fi
|
|
14 |
st.set_page_config(page_title="Fake News Detector", layout="wide")
|
15 |
st.title("π° Fake News Detector")
|
16 |
|
17 |
-
# Tabs for Input and Results
|
18 |
-
tab1, tab2 = st.tabs(["Input", "Results"])
|
19 |
-
|
20 |
# Function to fetch real news links from various open sources
|
21 |
def fetch_real_news_links():
|
22 |
return [
|
@@ -29,59 +26,58 @@ def fetch_real_news_links():
|
|
29 |
"https://www.factcheck.org"
|
30 |
]
|
31 |
|
32 |
-
|
33 |
-
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
if not news_text.strip():
|
40 |
-
st.warning("Please enter some text.")
|
41 |
-
else:
|
42 |
-
st.session_state["news_text"] = news_text
|
43 |
-
st.session_state["analyze"] = True
|
44 |
-
st.rerun()
|
45 |
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
st.image(uploaded_file, caption="Uploaded Image", use_column_width=True)
|
50 |
-
st.info("π Image analysis coming soon!")
|
51 |
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
|
|
59 |
|
60 |
-
|
61 |
-
|
62 |
news_text = st.session_state.get("news_text", "")
|
63 |
-
|
64 |
-
|
|
|
65 |
hf_result = fake_news_pipeline(news_text)[0]['label'].lower()
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
st.subheader("π Reliable News Sources")
|
86 |
-
for link in fetch_real_news_links():
|
87 |
-
st.markdown(f"[π {link}]({link})")
|
|
|
14 |
st.set_page_config(page_title="Fake News Detector", layout="wide")
|
15 |
st.title("π° Fake News Detector")
|
16 |
|
|
|
|
|
|
|
17 |
# Function to fetch real news links from various open sources
|
18 |
def fetch_real_news_links():
|
19 |
return [
|
|
|
26 |
"https://www.factcheck.org"
|
27 |
]
|
28 |
|
29 |
+
# Input Section
|
30 |
+
st.sidebar.title("Select Input Type")
|
31 |
+
option = st.sidebar.radio("Choose an option", ["Text", "Image", "Video Link"])
|
32 |
+
|
33 |
+
if option == "Text":
|
34 |
+
news_text = st.text_area("Enter the news content to check:", height=200)
|
35 |
+
analyze_text = st.button("Analyze Text")
|
36 |
+
|
37 |
+
elif option == "Image":
|
38 |
+
uploaded_file = st.file_uploader("Upload an image of a news article", type=["jpg", "png", "jpeg"])
|
39 |
+
analyze_image = st.button("Analyze Image")
|
40 |
|
41 |
+
elif option == "Video Link":
|
42 |
+
video_url = st.text_input("Enter a video news link to check")
|
43 |
+
analyze_video = st.button("Analyze Video")
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
+
# Results Section
|
46 |
+
if "analyze" not in st.session_state:
|
47 |
+
st.session_state["analyze"] = False
|
|
|
|
|
48 |
|
49 |
+
if (option == "Text" and analyze_text and news_text.strip()) or \
|
50 |
+
(option == "Image" and analyze_image and uploaded_file) or \
|
51 |
+
(option == "Video Link" and analyze_video and video_url.strip()):
|
52 |
+
st.session_state["analyze"] = True
|
53 |
+
st.session_state["news_text"] = news_text if option == "Text" else ""
|
54 |
+
st.session_state["uploaded_file"] = uploaded_file if option == "Image" else None
|
55 |
+
st.session_state["video_url"] = video_url if option == "Video Link" else ""
|
56 |
+
st.rerun()
|
57 |
|
58 |
+
if st.session_state["analyze"]:
|
59 |
+
with st.spinner("Analyzing..."):
|
60 |
news_text = st.session_state.get("news_text", "")
|
61 |
+
hf_result = "uncertain"
|
62 |
+
|
63 |
+
if news_text:
|
64 |
hf_result = fake_news_pipeline(news_text)[0]['label'].lower()
|
65 |
+
|
66 |
+
if hf_result == "fake":
|
67 |
+
st.error("β This news is likely **Fake**!", icon="β οΈ")
|
68 |
+
conclusion = "The analysis suggests that this news might be fabricated or misleading. Please verify from credible sources."
|
69 |
+
elif hf_result == "real":
|
70 |
+
st.success("β
This news is likely **Real**!", icon="β
")
|
71 |
+
conclusion = "The analysis indicates that this news appears to be credible and factual."
|
72 |
+
else:
|
73 |
+
st.info("π€ The result is uncertain. Please verify from trusted sources.")
|
74 |
+
conclusion = "There is uncertainty in the classification. Further verification is recommended."
|
75 |
+
|
76 |
+
# Conclusion Section
|
77 |
+
st.subheader("π Conclusion")
|
78 |
+
st.write(conclusion)
|
79 |
+
|
80 |
+
# Display real news sources
|
81 |
+
st.subheader("π Reliable News Sources")
|
82 |
+
for link in fetch_real_news_links():
|
83 |
+
st.markdown(f"[π {link}]({link})")
|
|
|
|
|
|