asad231 commited on
Commit
e8ac83a
Β·
verified Β·
1 Parent(s): 520030f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -51
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="MoritzLaurer/deberta-v3-large-contrastive-fake-news")
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
- # # ---- 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
- 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
- # βœ… Get Model Prediction
188
- prediction = fake_news_detector(news_input)
189
- label = prediction[0]['label'].lower()
190
- confidence = prediction[0]['score']
191
-
192
- # βœ… Ensure Correct Classification
193
- if "fake" in label or confidence < 0.5:
194
- st.error(f"⚠️ Result: This news is **FAKE**. (Confidence: {confidence:.2f})")
195
  else:
196
- st.success(f"βœ… Result: This news is **REAL**. (Confidence: {confidence:.2f})")
 
 
 
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")