asad231 commited on
Commit
bde75ba
Β·
verified Β·
1 Parent(s): 10c4ed3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -13
app.py CHANGED
@@ -141,23 +141,34 @@ def detect_deepfake_image(image_path):
141
  st.subheader("πŸ“ Fake News Detection")
142
  news_input = st.text_area("Enter News Text:", placeholder="Type here...")
143
 
 
 
 
 
 
 
 
 
 
 
 
144
  if st.button("Check News"):
145
  st.write("πŸ” Processing...")
146
- prediction = fake_news_detector(news_input)
147
- label = prediction[0]['label'].lower() # Convert label to lowercase
148
- confidence = prediction[0]['score']
149
-
150
- # Force classification based on confidence threshold
151
- threshold = 0.5 # Adjust if needed
152
- if confidence >= threshold:
153
- if "fake" in label or "false" in label or "negative" in label:
154
- st.error(f"⚠️ Result: This news is **FAKE**. (Confidence: {confidence:.2f})")
155
  else:
156
- st.success(f"βœ… Result: This news is **REAL**. (Confidence: {confidence:.2f})")
157
  else:
158
- # If confidence is too low, classify based on probability
159
- final_label = "FAKE" if confidence < 0.5 else "REAL"
160
- if final_label == "FAKE":
 
 
 
161
  st.error(f"⚠️ Result: This news is **FAKE**. (Confidence: {confidence:.2f})")
162
  else:
163
  st.success(f"βœ… Result: This news is **REAL**. (Confidence: {confidence:.2f})")
 
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})")