File size: 2,615 Bytes
65d7807
 
9f4ba8d
8af7545
b60c78b
3f3b7d6
b60c78b
 
36aa3f5
65d7807
de25c83
 
 
65d7807
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
de25c83
 
 
65d7807
 
 
 
a796eab
267ab6e
3f3b7d6
 
 
 
 
 
 
 
 
 
65d7807
9263dfd
2402e03
9263dfd
70fb4f0
dbee40e
 
 
 
 
722e05d
65d7807
9263dfd
 
9604e0d
722e05d
f6a5f9f
 
 
 
65d7807
0e6a636
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import gradio as gr
from huggingface_hub import from_pretrained_keras
from huggingface_hub import KerasModelHubMixin
import transformers
from transformers import AutoTokenizer
import numpy as np


m = from_pretrained_keras('sgonzalezsilot/FakeNews-Detection-Twitter-Thesis')

MODEL = "digitalepidemiologylab/covid-twitter-bert-v2"
tokenizer = AutoTokenizer.from_pretrained(MODEL)

def bert_encode(tokenizer,data,maximum_length) :
  input_ids = []
  attention_masks = []
  

  for i in range(len(data)):
      encoded = tokenizer.encode_plus(
        
        data[i],
        add_special_tokens=True,
        max_length=maximum_length,
        pad_to_max_length=True,
        truncation = True,
        return_attention_mask=True,
      )
      
      input_ids.append(encoded['input_ids'])
      attention_masks.append(encoded['attention_mask'])

  return np.array(input_ids),np.array(attention_masks)
    
# train_encodings = tokenizer(train_texts, truncation=True, padding=True)
# test_encodings = tokenizer(test_texts, truncation=True, padding=True)



    
def get_news(input_text):
  sentence_length = 110
  train_input_ids,train_attention_masks = bert_encode(tokenizer,[input_text],sentence_length)

  pred = m.predict([train_input_ids,train_attention_masks])
  pred = np.round(pred)
  pred = pred.flatten()

  if pred == 1:
      result = "Fake News"
  else:
      result = "True News"
  return result

tweet_input = gr.Textbox(label = "Enter the tweet")
output = gr.Textbox(label="Result")

descripcion = (
  """
  <center>
  Demo of the Covid-Twitter Fake News Detection System from my thesis.
  </center>
  """
)
iface = gr.Interface(fn = get_news, 
                     inputs = tweet_input, 
                     outputs = output,
                     title = 'Covid Fake News Detection System', 
                     description=descripcion,
                     examples=["CDC Recommends Mothers Stop Breastfeeding To Boost Vaccine Efficacy",
                               "An article claiming that Bill Gates' vaccine would modify human DNA.",
                               "In the first half of 2020 WHO coordinated the logistics &amp; shipped 😷More than 3M surgical masks 🧤More than 2M gloves 🧰More than 1M diagnostic kits 🥼More than 200K gowns 🛡️More than 100K face shields to 135 countries across the🌍🌎🌏. https://t.co/iz4YQkbSGM",
                               "Many COVID-19 treatments may be associated with adverse skin reactions and should be considered in a differential diagnosis new report says. https://t.co/GLSeYX2VDq"])
                     
iface.launch()