syeda-Rija20 commited on
Commit
b261acc
·
verified ·
1 Parent(s): 68ae53c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -7
app.py CHANGED
@@ -39,7 +39,7 @@ st.caption("Multi-Modal Fake News & AI Image Detection System")
39
  def load_text_model():
40
  # model_name = "Maheentouqeer1/truthguard-fake-news-detector"
41
  # NEW - replace with this well-trained model
42
- model_name = "GonzaloA/fake-news-detector"
43
  tokenizer = AutoTokenizer.from_pretrained(model_name)
44
  model = AutoModelForSequenceClassification.from_pretrained(
45
  model_name, low_cpu_mem_usage=True
@@ -94,7 +94,10 @@ def predict_news(text, tokenizer, text_model):
94
  probs = torch.nn.functional.softmax(outputs.logits, dim=1)
95
  prediction = torch.argmax(probs).item()
96
  confidence = torch.max(probs).item() * 100
97
- return prediction, confidence
 
 
 
98
  # ---------------------------
99
  # PREDICT IMAGE
100
  # ---------------------------
@@ -128,13 +131,13 @@ with tab1:
128
  if user_input.strip() == "":
129
  st.warning("Please enter some text")
130
  else:
131
- pred, conf = predict_news(user_input, tokenizer, text_model)
132
- if pred == 0:
 
133
  st.error(f"⚠️ FAKE NEWS ({conf:.2f}%)")
134
- elif pred == 1:
135
- st.success(f"✅ REAL NEWS ({conf:.2f}%)")
136
  else:
137
- st.warning(f"🤔 UNCERTAIN ({conf:.2f}%)")
 
138
  st.progress(int(conf))
139
 
140
  with tab2:
 
39
  def load_text_model():
40
  # model_name = "Maheentouqeer1/truthguard-fake-news-detector"
41
  # NEW - replace with this well-trained model
42
+ model_name = "hamzab/roberta-fake-news-classification"
43
  tokenizer = AutoTokenizer.from_pretrained(model_name)
44
  model = AutoModelForSequenceClassification.from_pretrained(
45
  model_name, low_cpu_mem_usage=True
 
94
  probs = torch.nn.functional.softmax(outputs.logits, dim=1)
95
  prediction = torch.argmax(probs).item()
96
  confidence = torch.max(probs).item() * 100
97
+
98
+ # This model outputs: 0 = FAKE, 1 = REAL
99
+ label = text_model.config.id2label[prediction]
100
+ return label, confidence
101
  # ---------------------------
102
  # PREDICT IMAGE
103
  # ---------------------------
 
131
  if user_input.strip() == "":
132
  st.warning("Please enter some text")
133
  else:
134
+ label, conf = predict_news(user_input, tokenizer, text_model)
135
+
136
+ if label == "FAKE":
137
  st.error(f"⚠️ FAKE NEWS ({conf:.2f}%)")
 
 
138
  else:
139
+ st.success(f" REAL NEWS ({conf:.2f}%)")
140
+
141
  st.progress(int(conf))
142
 
143
  with tab2: