Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,15 +1,15 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from transformers import pipeline, AutoConfig,
|
| 3 |
|
| 4 |
model_id = "KenLumod/ML-Fake-Real-News-Detector-Final"
|
| 5 |
|
| 6 |
# Force reload model with updated config
|
| 7 |
config = AutoConfig.from_pretrained(model_id)
|
| 8 |
-
config.id2label = {
|
| 9 |
config.label2id = {v: k for k, v in config.id2label.items()}
|
| 10 |
|
| 11 |
-
# Load the model using
|
| 12 |
-
model =
|
| 13 |
|
| 14 |
# Create the pipeline for classification
|
| 15 |
classifier = pipeline(
|
|
@@ -21,6 +21,7 @@ classifier = pipeline(
|
|
| 21 |
|
| 22 |
def classify_news(text):
|
| 23 |
result = classifier(text)[0]
|
|
|
|
| 24 |
return result['label']
|
| 25 |
|
| 26 |
demo = gr.Interface(
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import pipeline, AutoConfig, AutoModelForSequenceClassification
|
| 3 |
|
| 4 |
model_id = "KenLumod/ML-Fake-Real-News-Detector-Final"
|
| 5 |
|
| 6 |
# Force reload model with updated config
|
| 7 |
config = AutoConfig.from_pretrained(model_id)
|
| 8 |
+
config.id2label = {0: "Fake News", 1: "Real News"} # Force override
|
| 9 |
config.label2id = {v: k for k, v in config.id2label.items()}
|
| 10 |
|
| 11 |
+
# Load the model using AutoModelForSequenceClassification
|
| 12 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_id, config=config)
|
| 13 |
|
| 14 |
# Create the pipeline for classification
|
| 15 |
classifier = pipeline(
|
|
|
|
| 21 |
|
| 22 |
def classify_news(text):
|
| 23 |
result = classifier(text)[0]
|
| 24 |
+
print(result) # Inspect the output
|
| 25 |
return result['label']
|
| 26 |
|
| 27 |
demo = gr.Interface(
|