Update app.py
Browse files
app.py
CHANGED
|
@@ -137,42 +137,58 @@ def detect_deepfake_image(image_path):
|
|
| 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 |
-
#
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 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")
|
| 178 |
uploaded_image = st.file_uploader("Upload an Image", type=["jpg", "png", "jpeg"])
|
|
|
|
| 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 |
# ---- Fake News Detection Section ----
|
| 176 |
st.subheader("π Fake News Detection")
|
| 177 |
news_input = st.text_area("Enter News Text:", placeholder="Type here...")
|
| 178 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 179 |
if st.button("Check News"):
|
| 180 |
st.write("π Processing...")
|
| 181 |
|
| 182 |
+
# Use AI model to classify the news
|
| 183 |
+
prediction = fake_news_detector(news_input)
|
| 184 |
+
label = prediction[0]['label'].lower()
|
| 185 |
+
confidence = prediction[0]['score']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 186 |
|
| 187 |
+
# Ensure correct classification
|
| 188 |
+
if label in ["fake", "false", "negative"] or confidence < 0.5:
|
| 189 |
+
st.error(f"β οΈ Result: This news is **FAKE**. (Confidence: {confidence:.2f})")
|
| 190 |
+
else:
|
| 191 |
+
st.success(f"β
Result: This news is **REAL**. (Confidence: {confidence:.2f})")
|
| 192 |
# ---- Deepfake Image Detection Section ----
|
| 193 |
st.subheader("πΈ Deepfake Image Detection")
|
| 194 |
uploaded_image = st.file_uploader("Upload an Image", type=["jpg", "png", "jpeg"])
|