Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,6 @@ from transformers import pipeline
|
|
4 |
from PIL import Image
|
5 |
import torch
|
6 |
import torchvision.transforms as transforms
|
7 |
-
import io
|
8 |
|
9 |
# Load Fake News Detection Model from Hugging Face
|
10 |
fake_news_pipeline = pipeline("text-classification", model="mrm8488/bert-tiny-finetuned-fake-news-detection")
|
@@ -28,43 +27,50 @@ def verify_news(news_text):
|
|
28 |
st.set_page_config(page_title="Fake News Detector", layout="wide")
|
29 |
st.title("π° Fake News Detector")
|
30 |
|
31 |
-
#
|
32 |
-
|
33 |
-
if key not in st.session_state:
|
34 |
-
st.session_state[key] = None
|
35 |
|
36 |
-
# Input Section
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
-
|
42 |
-
|
43 |
-
st.
|
44 |
-
st.
|
45 |
-
st.
|
46 |
-
|
|
|
|
|
|
|
|
|
47 |
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
st.
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
if analyze_video_clicked and video_url.strip():
|
62 |
-
st.session_state["video_url"] = video_url
|
63 |
-
st.session_state["analyze_video"] = True
|
64 |
|
65 |
# Results Section
|
66 |
st.subheader("π Analysis Results")
|
67 |
-
if st.session_state
|
68 |
result = st.session_state.get("result_text")
|
69 |
accuracy = st.session_state.get("accuracy_text")
|
70 |
verification_link = verify_news(st.session_state.get("news_text"))
|
@@ -88,13 +94,3 @@ if st.session_state.get("analyze_text", False):
|
|
88 |
for link in sources:
|
89 |
st.markdown(f"[π {link}]({link})")
|
90 |
st.markdown(f"[π Verify on Google]({verification_link})")
|
91 |
-
|
92 |
-
if st.session_state.get("analyze_image", False):
|
93 |
-
image = st.session_state.get("news_image")
|
94 |
-
st.image(image, caption="Uploaded Image", use_column_width=True)
|
95 |
-
st.info(analyze_image(image))
|
96 |
-
|
97 |
-
if st.session_state.get("analyze_video", False):
|
98 |
-
video_url = st.session_state.get("video_url", "")
|
99 |
-
st.video(video_url)
|
100 |
-
st.info("Video analysis feature coming soon!")
|
|
|
4 |
from PIL import Image
|
5 |
import torch
|
6 |
import torchvision.transforms as transforms
|
|
|
7 |
|
8 |
# Load Fake News Detection Model from Hugging Face
|
9 |
fake_news_pipeline = pipeline("text-classification", model="mrm8488/bert-tiny-finetuned-fake-news-detection")
|
|
|
27 |
st.set_page_config(page_title="Fake News Detector", layout="wide")
|
28 |
st.title("π° Fake News Detector")
|
29 |
|
30 |
+
# Dividing Input Section
|
31 |
+
col1, col2, col3 = st.columns(3)
|
|
|
|
|
32 |
|
33 |
+
# Text Input Section
|
34 |
+
with col1:
|
35 |
+
st.subheader("π Enter Text")
|
36 |
+
news_text = st.text_area("Enter the news content to check:", height=150)
|
37 |
+
analyze_text_clicked = st.button("Analyze News")
|
38 |
+
if analyze_text_clicked:
|
39 |
+
if not news_text.strip():
|
40 |
+
st.warning("Please enter some text.")
|
41 |
+
else:
|
42 |
+
result, accuracy = classify_text(news_text)
|
43 |
+
st.session_state["news_text"] = news_text
|
44 |
+
st.session_state["result_text"] = result
|
45 |
+
st.session_state["accuracy_text"] = accuracy
|
46 |
|
47 |
+
# Image Upload Section
|
48 |
+
with col2:
|
49 |
+
st.subheader("πΌοΈ Upload Image")
|
50 |
+
uploaded_image = st.file_uploader("Upload a news image", type=["jpg", "png", "jpeg"])
|
51 |
+
analyze_image_clicked = st.button("Analyze Image")
|
52 |
+
if uploaded_image and analyze_image_clicked:
|
53 |
+
image = Image.open(uploaded_image)
|
54 |
+
st.session_state["news_image"] = image
|
55 |
+
st.image(image, caption="Uploaded Image", use_column_width=True)
|
56 |
+
st.info(analyze_image(image))
|
57 |
|
58 |
+
# Video Link Input Section
|
59 |
+
with col3:
|
60 |
+
st.subheader("π₯ Enter Video Link")
|
61 |
+
video_url = st.text_input("Enter the video link:")
|
62 |
+
analyze_video_clicked = st.button("Analyze Video")
|
63 |
+
if analyze_video_clicked:
|
64 |
+
if not video_url.strip():
|
65 |
+
st.warning("Please enter a valid video link.")
|
66 |
+
else:
|
67 |
+
st.session_state["video_url"] = video_url
|
68 |
+
st.video(video_url)
|
69 |
+
st.info("Video analysis feature coming soon!")
|
|
|
|
|
|
|
|
|
70 |
|
71 |
# Results Section
|
72 |
st.subheader("π Analysis Results")
|
73 |
+
if "result_text" in st.session_state:
|
74 |
result = st.session_state.get("result_text")
|
75 |
accuracy = st.session_state.get("accuracy_text")
|
76 |
verification_link = verify_news(st.session_state.get("news_text"))
|
|
|
94 |
for link in sources:
|
95 |
st.markdown(f"[π {link}]({link})")
|
96 |
st.markdown(f"[π Verify on Google]({verification_link})")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|