Update app.py
Browse files
app.py
CHANGED
@@ -104,7 +104,7 @@ st.title("π° Fake News & Deepfake Detection Tool")
|
|
104 |
st.write("π Detect Fake News, Deepfake Images, and Videos using AI")
|
105 |
|
106 |
# Load Models
|
107 |
-
fake_news_detector = pipeline("text-classification", model="
|
108 |
|
109 |
# Load Deepfake Detection Models
|
110 |
base_model_image = Xception(weights="imagenet", include_top=False)
|
@@ -137,64 +137,41 @@ def detect_deepfake_image(image_path):
|
|
137 |
label = "FAKE" if confidence > 0.5 else "REAL"
|
138 |
return {"label": label, "score": confidence}
|
139 |
|
140 |
-
#
|
141 |
-
# st.subheader("π Fake News Detection")
|
142 |
-
# news_input = st.text_area("Enter News Text:", placeholder="Type here...")
|
143 |
-
|
144 |
-
# # Manually verified facts database (you can expand this)
|
145 |
-
# fact_check_db = {
|
146 |
-
# "elon musk was born in 1932": "FAKE",
|
147 |
-
# "earth revolves around the sun": "REAL",
|
148 |
-
# "the moon is made of cheese": "FAKE",
|
149 |
-
# }
|
150 |
-
|
151 |
-
# def check_manual_facts(text):
|
152 |
-
# text_lower = text.lower().strip()
|
153 |
-
# return fact_check_db.get(text_lower, None)
|
154 |
-
|
155 |
-
# if st.button("Check News"):
|
156 |
-
# st.write("π Processing...")
|
157 |
-
|
158 |
-
# # Check if the news is in the fact-check database
|
159 |
-
# manual_result = check_manual_facts(news_input)
|
160 |
-
# if manual_result:
|
161 |
-
# if manual_result == "FAKE":
|
162 |
-
# st.error(f"β οΈ Result: This news is **FAKE** (Verified by Database).")
|
163 |
-
# else:
|
164 |
-
# st.success(f"β
Result: This news is **REAL** (Verified by Database).")
|
165 |
-
# else:
|
166 |
-
# # Use AI model if fact is not in the database
|
167 |
-
# prediction = fake_news_detector(news_input)
|
168 |
-
# label = prediction[0]['label'].lower()
|
169 |
-
# confidence = prediction[0]['score']
|
170 |
-
|
171 |
-
# if "fake" in label or confidence < 0.5:
|
172 |
-
# st.error(f"β οΈ Result: This news is **FAKE**. (Confidence: {confidence:.2f})")
|
173 |
-
# else:
|
174 |
-
# st.success(f"β
Result: This news is **REAL**. (Confidence: {confidence:.2f})")
|
175 |
-
from transformers import pipeline
|
176 |
-
import streamlit as st
|
177 |
-
|
178 |
-
# β
Load a Valid Fake News Detection Model
|
179 |
-
fake_news_detector = pipeline("text-classification", model="MoritzLaurer/deberta-v3-large-contrastive-fake-news")
|
180 |
-
|
181 |
st.subheader("π Fake News Detection")
|
182 |
news_input = st.text_area("Enter News Text:", placeholder="Type here...")
|
183 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
184 |
if st.button("Check News"):
|
185 |
st.write("π Processing...")
|
186 |
|
187 |
-
#
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
st.error(f"β οΈ Result: This news is **FAKE**. (Confidence: {confidence:.2f})")
|
195 |
else:
|
196 |
-
|
|
|
|
|
|
|
197 |
|
|
|
|
|
|
|
|
|
198 |
|
199 |
# ---- Deepfake Image Detection Section ----
|
200 |
st.subheader("πΈ Deepfake Image Detection")
|
|
|
104 |
st.write("π Detect Fake News, Deepfake Images, and Videos using AI")
|
105 |
|
106 |
# Load Models
|
107 |
+
fake_news_detector = pipeline("text-classification", model="microsoft/deberta-v3-base")
|
108 |
|
109 |
# Load Deepfake Detection Models
|
110 |
base_model_image = Xception(weights="imagenet", include_top=False)
|
|
|
137 |
label = "FAKE" if confidence > 0.5 else "REAL"
|
138 |
return {"label": label, "score": confidence}
|
139 |
|
140 |
+
# ---- Fake News Detection Section ----
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
st.subheader("π Fake News Detection")
|
142 |
news_input = st.text_area("Enter News Text:", placeholder="Type here...")
|
143 |
|
144 |
+
# Manually verified facts database (you can expand this)
|
145 |
+
fact_check_db = {
|
146 |
+
"elon musk was born in 1932": "FAKE",
|
147 |
+
"earth revolves around the sun": "REAL",
|
148 |
+
"the moon is made of cheese": "FAKE",
|
149 |
+
}
|
150 |
+
|
151 |
+
def check_manual_facts(text):
|
152 |
+
text_lower = text.lower().strip()
|
153 |
+
return fact_check_db.get(text_lower, None)
|
154 |
+
|
155 |
if st.button("Check News"):
|
156 |
st.write("π Processing...")
|
157 |
|
158 |
+
# Check if the news is in the fact-check database
|
159 |
+
manual_result = check_manual_facts(news_input)
|
160 |
+
if manual_result:
|
161 |
+
if manual_result == "FAKE":
|
162 |
+
st.error(f"β οΈ Result: This news is **FAKE** (Verified by Database).")
|
163 |
+
else:
|
164 |
+
st.success(f"β
Result: This news is **REAL** (Verified by Database).")
|
|
|
165 |
else:
|
166 |
+
# Use AI model if fact is not in the database
|
167 |
+
prediction = fake_news_detector(news_input)
|
168 |
+
label = prediction[0]['label'].lower()
|
169 |
+
confidence = prediction[0]['score']
|
170 |
|
171 |
+
if "fake" in label or confidence < 0.5:
|
172 |
+
st.error(f"β οΈ Result: This news is **FAKE**. (Confidence: {confidence:.2f})")
|
173 |
+
else:
|
174 |
+
st.success(f"β
Result: This news is **REAL**. (Confidence: {confidence:.2f})")
|
175 |
|
176 |
# ---- Deepfake Image Detection Section ----
|
177 |
st.subheader("πΈ Deepfake Image Detection")
|