File size: 1,591 Bytes
65d7807
 
9f4ba8d
8af7545
b60c78b
 
 
36aa3f5
 
65d7807
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b60c78b
65d7807
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from huggingface_hub import from_pretrained_keras
from huggingface_hub import KerasModelHubMixin
import transformers
from transformers import AutoTokenizer


m = from_pretrained_keras('sgonzalezsilot/FakeNews-Detection-Twitter-Thesis')
# model = from_pretrained_keras("keras-io/cct")

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)

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

sentence_length = 110
train_input_ids,train_attention_masks = bert_encode(tokenizer,train_texts,sentence_length)
test_input_ids,test_attention_masks = bert_encode(tokenizer,test_texts,sentence_length)
    
def get_news(input_text):
  return sentiment(input_text)

iface = gr.Interface(fn = get_news, 
                     inputs = "text", 
                     outputs = ['text'],
                     title = 'Fake News', 
                     description="")
                     
iface.launch(inline = False)