Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -10,11 +10,12 @@ import io
|
|
10 |
fake_news_pipeline = pipeline("text-classification", model="mrm8488/bert-tiny-finetuned-fake-news-detection")
|
11 |
|
12 |
def classify_text(news_text):
|
13 |
-
result = fake_news_pipeline(news_text)[0]
|
14 |
-
|
|
|
|
|
15 |
|
16 |
def analyze_image(image):
|
17 |
-
# Convert image to tensor (Placeholder: Model should be updated with a real image classifier)
|
18 |
transform = transforms.Compose([transforms.Resize((224, 224)), transforms.ToTensor()])
|
19 |
image_tensor = transform(image).unsqueeze(0)
|
20 |
return "Image analysis feature coming soon!"
|
@@ -27,76 +28,72 @@ def verify_news(news_text):
|
|
27 |
st.set_page_config(page_title="Fake News Detector", layout="wide")
|
28 |
st.title("π° Fake News Detector")
|
29 |
|
30 |
-
#
|
31 |
-
|
|
|
32 |
|
33 |
-
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
else:
|
44 |
-
st.session_state["news_text"] = news_text
|
45 |
-
st.session_state["analyze_text"] = True
|
46 |
-
st.rerun()
|
47 |
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
if
|
52 |
-
|
53 |
-
|
54 |
-
st.session_state["
|
55 |
-
st.
|
56 |
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
result = classify_text(news_text)
|
73 |
-
verification_link = verify_news(news_text)
|
74 |
-
|
75 |
-
if result == "Fake":
|
76 |
-
st.error("β This news is likely **Fake**!", icon="β οΈ")
|
77 |
-
st.markdown("<style>div.stAlert {background-color: #FFCCCC;}</style>", unsafe_allow_html=True)
|
78 |
-
else:
|
79 |
-
st.success("β
This news is likely **Real**!", icon="β
")
|
80 |
-
st.markdown("<style>div.stAlert {background-color: #CCFFCC;}</style>", unsafe_allow_html=True)
|
81 |
-
|
82 |
-
st.subheader("π Verification & Trusted Sources")
|
83 |
-
sources = [
|
84 |
-
"https://www.bbc.com/news",
|
85 |
-
"https://www.cnn.com",
|
86 |
-
"https://www.reuters.com",
|
87 |
-
"https://huggingface.co/datasets",
|
88 |
-
"https://wildfireai.com/deepfake-detection"
|
89 |
-
]
|
90 |
-
for link in sources:
|
91 |
-
st.markdown(f"[π {link}]({link})")
|
92 |
-
st.markdown(f"[π Verify on Google]({verification_link})")
|
93 |
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
if st.session_state.get("analyze_video", False):
|
100 |
-
video_url = st.session_state.get("video_url", "")
|
101 |
-
st.video(video_url)
|
102 |
-
st.info("Video analysis feature coming soon!")
|
|
|
10 |
fake_news_pipeline = pipeline("text-classification", model="mrm8488/bert-tiny-finetuned-fake-news-detection")
|
11 |
|
12 |
def classify_text(news_text):
|
13 |
+
result = fake_news_pipeline(news_text)[0]
|
14 |
+
label = result['label'].lower()
|
15 |
+
score = result['score'] * 100 # Convert to percentage
|
16 |
+
return ("Fake" if label == "fake" else "Real"), round(score, 2)
|
17 |
|
18 |
def analyze_image(image):
|
|
|
19 |
transform = transforms.Compose([transforms.Resize((224, 224)), transforms.ToTensor()])
|
20 |
image_tensor = transform(image).unsqueeze(0)
|
21 |
return "Image analysis feature coming soon!"
|
|
|
28 |
st.set_page_config(page_title="Fake News Detector", layout="wide")
|
29 |
st.title("π° Fake News Detector")
|
30 |
|
31 |
+
# Sidebar for Input Selection
|
32 |
+
st.sidebar.title("Select Input Type")
|
33 |
+
option = st.sidebar.radio("Choose an option", ["Text", "Image", "Video Link"])
|
34 |
|
35 |
+
# Input Section
|
36 |
+
if option == "Text":
|
37 |
+
news_text = st.text_area("Enter the news content to check:", height=200)
|
38 |
+
if st.button("Analyze News", key="analyze_text"):
|
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["analyze_text"] = True
|
45 |
+
st.session_state["result_text"] = result
|
46 |
+
st.session_state["accuracy_text"] = accuracy
|
47 |
|
48 |
+
elif option == "Image":
|
49 |
+
uploaded_image = st.file_uploader("Upload a news image", type=["jpg", "png", "jpeg"])
|
50 |
+
if uploaded_image and st.button("Analyze Image", key="analyze_image"):
|
51 |
+
image = Image.open(uploaded_image)
|
52 |
+
st.session_state["news_image"] = image
|
53 |
+
st.session_state["analyze_image"] = True
|
|
|
|
|
|
|
|
|
54 |
|
55 |
+
elif option == "Video Link":
|
56 |
+
video_url = st.text_input("Enter the video link:")
|
57 |
+
if st.button("Analyze Video", key="analyze_video"):
|
58 |
+
if not video_url.strip():
|
59 |
+
st.warning("Please enter a valid video link.")
|
60 |
+
else:
|
61 |
+
st.session_state["video_url"] = video_url
|
62 |
+
st.session_state["analyze_video"] = True
|
63 |
|
64 |
+
# Results Section
|
65 |
+
st.subheader("π Analysis Results")
|
66 |
+
if st.session_state.get("analyze_text", False):
|
67 |
+
result = st.session_state.get("result_text")
|
68 |
+
accuracy = st.session_state.get("accuracy_text")
|
69 |
+
verification_link = verify_news(st.session_state.get("news_text"))
|
70 |
+
|
71 |
+
if result == "Fake":
|
72 |
+
st.error(f"β This news is likely **Fake**! (Accuracy: {accuracy}%)", icon="β οΈ")
|
73 |
+
else:
|
74 |
+
st.success(f"β
This news is likely **Real**! (Accuracy: {accuracy}%)", icon="β
")
|
75 |
+
|
76 |
+
st.subheader("π Verification & Trusted Sources")
|
77 |
+
sources = [
|
78 |
+
"https://www.bbc.com/news",
|
79 |
+
"https://www.cnn.com",
|
80 |
+
"https://www.reuters.com",
|
81 |
+
"https://factcheck.org",
|
82 |
+
"https://www.snopes.com",
|
83 |
+
"https://www.politifact.com",
|
84 |
+
"https://deepfake-o-meter.ai",
|
85 |
+
"https://huggingface.co/models?pipeline_tag=text-classification"
|
86 |
+
]
|
87 |
+
for link in sources:
|
88 |
+
st.markdown(f"[οΏ½οΏ½οΏ½οΏ½ {link}]({link})")
|
89 |
+
st.markdown(f"[π Verify on Google]({verification_link})")
|
90 |
|
91 |
+
if st.session_state.get("analyze_image", False):
|
92 |
+
image = st.session_state.get("news_image")
|
93 |
+
st.image(image, caption="Uploaded Image", use_column_width=True)
|
94 |
+
st.info(analyze_image(image))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
|
96 |
+
if st.session_state.get("analyze_video", False):
|
97 |
+
video_url = st.session_state.get("video_url", "")
|
98 |
+
st.video(video_url)
|
99 |
+
st.info("Video analysis feature coming soon!")
|
|
|
|
|
|
|
|
|
|