Spaces:
Sleeping
Sleeping
Commit
Β·
e20d2a1
1
Parent(s):
734d9e9
oled version
Browse files
app.py
CHANGED
@@ -1,43 +1,51 @@
|
|
1 |
import streamlit as st
|
2 |
-
from transformers import
|
3 |
from peft import PeftModel
|
4 |
import torch
|
5 |
-
|
|
|
6 |
@st.cache_resource
|
7 |
def load_model():
|
8 |
base_model = "Qwen/Qwen3-0.6B"
|
9 |
adapter_path = "faizabenatmane/Qwen-3-0.6B"
|
10 |
|
11 |
tokenizer = AutoTokenizer.from_pretrained(base_model)
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
model = PeftModel.from_pretrained(base, adapter_path)
|
15 |
model = model.merge_and_unload()
|
16 |
|
17 |
-
|
|
|
18 |
return pipe
|
19 |
|
20 |
-
|
|
|
21 |
|
22 |
-
# Streamlit UI
|
23 |
-
st.title("π° Fake News Detection
|
24 |
text = st.text_area("Enter a news statement or claim:", height=200)
|
25 |
|
26 |
if st.button("Check"):
|
27 |
with st.spinner("Analyzing..."):
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
31 |
|
32 |
-
|
33 |
-
|
34 |
verdict = "Real"
|
35 |
-
|
36 |
-
emoji = "β"
|
37 |
-
verdict = "Fake"
|
38 |
else:
|
39 |
-
|
40 |
-
|
41 |
|
|
|
42 |
st.subheader("Prediction")
|
43 |
-
st.success(f"{emoji} The statement is likely: **{verdict}**")
|
|
|
1 |
import streamlit as st
|
2 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline
|
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"
|
10 |
adapter_path = "faizabenatmane/Qwen-3-0.6B"
|
11 |
|
12 |
tokenizer = AutoTokenizer.from_pretrained(base_model)
|
13 |
+
|
14 |
+
base = AutoModelForSequenceClassification.from_pretrained(
|
15 |
+
base_model,
|
16 |
+
num_labels=2,
|
17 |
+
device_map="cpu"
|
18 |
+
)
|
19 |
|
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
|
31 |
+
st.title("π° Fake News Detection")
|
32 |
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})")
|