sgonzalezsilot commited on
Commit
05d6563
1 Parent(s): 7bb27c9

Copiando proyecto TFG

Browse files
Files changed (3) hide show
  1. README.md +3 -3
  2. app.py +75 -0
  3. requeriments.txt +3 -0
README.md CHANGED
@@ -1,8 +1,8 @@
1
  ---
2
  title: TFM DATCOM
3
- emoji: 🌖
4
- colorFrom: blue
5
- colorTo: green
6
  sdk: gradio
7
  sdk_version: 3.35.2
8
  app_file: app.py
 
1
  ---
2
  title: TFM DATCOM
3
+ emoji: 📰
4
+ colorFrom: red
5
+ colorTo: blue
6
  sdk: gradio
7
  sdk_version: 3.35.2
8
  app_file: app.py
app.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from huggingface_hub import from_pretrained_keras
3
+ from huggingface_hub import KerasModelHubMixin
4
+ import transformers
5
+ from transformers import AutoTokenizer
6
+ import numpy as np
7
+
8
+
9
+ m = from_pretrained_keras('sgonzalezsilot/FakeNews-Detection-Twitter-Thesis')
10
+
11
+ MODEL = "digitalepidemiologylab/covid-twitter-bert-v2"
12
+ tokenizer = AutoTokenizer.from_pretrained(MODEL)
13
+
14
+ def bert_encode(tokenizer,data,maximum_length) :
15
+ input_ids = []
16
+ attention_masks = []
17
+
18
+
19
+ for i in range(len(data)):
20
+ encoded = tokenizer.encode_plus(
21
+
22
+ data[i],
23
+ add_special_tokens=True,
24
+ max_length=maximum_length,
25
+ pad_to_max_length=True,
26
+ truncation = True,
27
+ return_attention_mask=True,
28
+ )
29
+
30
+ input_ids.append(encoded['input_ids'])
31
+ attention_masks.append(encoded['attention_mask'])
32
+
33
+ return np.array(input_ids),np.array(attention_masks)
34
+
35
+ # train_encodings = tokenizer(train_texts, truncation=True, padding=True)
36
+ # test_encodings = tokenizer(test_texts, truncation=True, padding=True)
37
+
38
+
39
+
40
+
41
+ def get_news(input_text):
42
+ sentence_length = 110
43
+ train_input_ids,train_attention_masks = bert_encode(tokenizer,[input_text],sentence_length)
44
+
45
+ pred = m.predict([train_input_ids,train_attention_masks])
46
+ pred = np.round(pred)
47
+ pred = pred.flatten()
48
+
49
+ if pred == 1:
50
+ result = "Fake News"
51
+ else:
52
+ result = "True News"
53
+ return result
54
+
55
+ tweet_input = gr.Textbox(label = "Enter the tweet")
56
+ output = gr.Textbox(label="Result")
57
+
58
+ descripcion = (
59
+ """
60
+ <center>
61
+ Demo of the Covid-Twitter Fake News Detection System from my thesis.
62
+ </center>
63
+ """
64
+ )
65
+ iface = gr.Interface(fn = get_news,
66
+ inputs = tweet_input,
67
+ outputs = output,
68
+ title = 'Covid Fake News Detection System',
69
+ description=descripcion,
70
+ examples=["CDC Recommends Mothers Stop Breastfeeding To Boost Vaccine Efficacy",
71
+ "An article claiming that Bill Gates' vaccine would modify human DNA.",
72
+ "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",
73
+ "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"])
74
+
75
+ iface.launch()
requeriments.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ tensorflow~=2.8
2
+ transformers
3
+ huggingface-hub