mrm8488 commited on
Commit
85e8ba7
1 Parent(s): 77e8bd1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -6
app.py CHANGED
@@ -1,21 +1,26 @@
1
  import gradio as gr
2
  import re
3
 
4
- from transformers import pipeline
5
 
6
- model = "Narrativaai/fake-news-detection-spanish"
7
- classifier = pipeline("text-classification", model=model)
8
 
 
9
 
10
- def predict(header, text):
 
 
 
 
 
11
  results = classifier(header + " [SEP] " + text)
12
  return results[0]["label"], round(results[0]["score"], 5)
13
 
14
 
15
  gradio_ui = gr.Interface(
16
- fn=predict,
17
  title="Fake News Detector (Spanish)",
18
- description="Enter some text and check if model detects bullying.",
19
  inputs=[
20
  gr.inputs.Textbox(lines=1, label="Type/Paste your headline here"),
21
  gr.inputs.Textbox(lines=6, label="Type/Paste the article body here"),
 
1
  import gradio as gr
2
  import re
3
 
4
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
5
 
6
+ ckpt = "Narrativaai/fake-news-detection-spanish"
 
7
 
8
+ tokenizer = AutoTokenizer.from_pretrained(ckpt)
9
 
10
+ model = AutoModelForSequenceClassification.from_pretrained(ckpt)
11
+
12
+ classifier = pipeline("text-classification", model=model, tokenizer=tokenizer)
13
+
14
+
15
+ def prediction(header, text):
16
  results = classifier(header + " [SEP] " + text)
17
  return results[0]["label"], round(results[0]["score"], 5)
18
 
19
 
20
  gradio_ui = gr.Interface(
21
+ fn=prediction,
22
  title="Fake News Detector (Spanish)",
23
+ description="Enter some text and check if it is Real or Fake",
24
  inputs=[
25
  gr.inputs.Textbox(lines=1, label="Type/Paste your headline here"),
26
  gr.inputs.Textbox(lines=6, label="Type/Paste the article body here"),