mohamedbmt commited on
Commit
26e5195
Β·
1 Parent(s): e20d2a1
Files changed (1) hide show
  1. app.py +7 -8
app.py CHANGED
@@ -3,7 +3,6 @@ from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipe
3
  from peft import PeftModel
4
  import torch
5
 
6
- # Load model and tokenizer with adapter
7
  @st.cache_resource
8
  def load_model():
9
  base_model = "Qwen/Qwen3-0.6B"
@@ -20,11 +19,9 @@ def load_model():
20
  model = PeftModel.from_pretrained(base, adapter_path)
21
  model = model.merge_and_unload()
22
 
23
- # βœ… Text classification pipeline
24
  pipe = pipeline("text-classification", model=model, tokenizer=tokenizer)
25
  return pipe
26
 
27
- # Load pipeline once
28
  classifier = load_model()
29
 
30
  # Streamlit UI
@@ -33,19 +30,21 @@ text = st.text_area("Enter a news statement or claim:", height=200)
33
 
34
  if st.button("Check"):
35
  with st.spinner("Analyzing..."):
36
- # Get classification result
37
  result = classifier(text)[0]
38
  label = result['label']
39
  score = result['score']
40
 
41
- # Optional: format label nicely
42
- if "1" in label or "POSITIVE" in label.upper():
 
43
  verdict = "Real"
44
  emoji = "βœ…"
45
- else:
46
  verdict = "Fake"
47
  emoji = "❌"
 
 
 
48
 
49
- # Show result
50
  st.subheader("Prediction")
51
  st.success(f"{emoji} The statement is likely: **{verdict}** (confidence: {score:.2f})")
 
3
  from peft import PeftModel
4
  import torch
5
 
 
6
  @st.cache_resource
7
  def load_model():
8
  base_model = "Qwen/Qwen3-0.6B"
 
19
  model = PeftModel.from_pretrained(base, adapter_path)
20
  model = model.merge_and_unload()
21
 
 
22
  pipe = pipeline("text-classification", model=model, tokenizer=tokenizer)
23
  return pipe
24
 
 
25
  classifier = load_model()
26
 
27
  # Streamlit UI
 
30
 
31
  if st.button("Check"):
32
  with st.spinner("Analyzing..."):
 
33
  result = classifier(text)[0]
34
  label = result['label']
35
  score = result['score']
36
 
37
+ st.write("πŸ”Ž Raw label:", label) # Debug print
38
+
39
+ if label == "LABEL_1":
40
  verdict = "Real"
41
  emoji = "βœ…"
42
+ elif label == "LABEL_0":
43
  verdict = "Fake"
44
  emoji = "❌"
45
+ else:
46
+ verdict = f"Unclear ({label})"
47
+ emoji = "πŸ€”"
48
 
 
49
  st.subheader("Prediction")
50
  st.success(f"{emoji} The statement is likely: **{verdict}** (confidence: {score:.2f})")