Spaces:
Runtime error
Runtime error
File size: 1,130 Bytes
77e8bd1 85e8ba7 77e8bd1 85e8ba7 77e8bd1 85e8ba7 77e8bd1 85e8ba7 77e8bd1 7e36559 77e8bd1 85e8ba7 77e8bd1 aa24955 77e8bd1 0a04b5e 0f9b4f9 aa24955 77e8bd1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
import gradio as gr
import re
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
ckpt = "Narrativaai/fake-news-detection-spanish"
tokenizer = AutoTokenizer.from_pretrained(ckpt)
model = AutoModelForSequenceClassification.from_pretrained(ckpt)
classifier = pipeline("text-classification", model=model, tokenizer=tokenizer)
def prediction(header, text):
results = classifier(header + " [SEP] " + text)
return results[0]["label"], results[0]["score"]
gradio_ui = gr.Interface(
fn=prediction,
title="Fake News Detector (Spanish)",
description="Type/Paste a post and check if it is Real or Fake",
inputs=[
gr.inputs.Textbox(lines=1, label="Type/Paste your headline here"),
gr.inputs.Textbox(lines=6, label="Type/Paste the article body here"),
],
outputs=[
gr.outputs.Textbox(label="Label"),
gr.outputs.Textbox(label="Score"),
],
examples=[
["El Real Madrid cerca de la bancarrota", "El Real Madrid cerca de la bancarrota"],
["El FC Barcelona está en bancarrota", ""],
]
)
gradio_ui.launch() |