Spaces:
Sleeping
Sleeping
Upload 7 files
Browse files- .gitattributes +1 -0
- Bi-LSTM-Model-1.h5 +3 -0
- CNN-Model-1.h5 +3 -0
- Fake_News_Detection_2_0 (4).ipynb +0 -0
- Twitter_Analysis.csv +3 -0
- app.py +91 -0
- c2_new_models2_weights.pt +3 -0
- requirements.txt +32 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
Twitter_Analysis.csv filter=lfs diff=lfs merge=lfs -text
|
Bi-LSTM-Model-1.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:40d9ea929f9fd7c72e8c53eaabef8e0a53774336d85f716d0e704dadfca1588b
|
| 3 |
+
size 17581304
|
CNN-Model-1.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ed6d529a612c98a14a56f52757fc54a8a8846e04d3120331b5d58ce8d80870f4
|
| 3 |
+
size 16450800
|
Fake_News_Detection_2_0 (4).ipynb
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
Twitter_Analysis.csv
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3d15543efca55929f5f27cf89791ee94974e28f4b9f0b6c3b8bbd0d548c17e8e
|
| 3 |
+
size 82375676
|
app.py
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import tweepy
|
| 3 |
+
import joblib
|
| 4 |
+
import torch
|
| 5 |
+
from transformers import BertTokenizer
|
| 6 |
+
|
| 7 |
+
# Load the tokenizer and the model
|
| 8 |
+
tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')
|
| 9 |
+
joblib.dump([model, bert], 'c2_new_models2_weights.pt')
|
| 10 |
+
|
| 11 |
+
def predict_fake_news(text):
|
| 12 |
+
# Tokenize and encode sequences
|
| 13 |
+
inputs = tokenizer.encode_plus(
|
| 14 |
+
text,
|
| 15 |
+
max_length=60,
|
| 16 |
+
pad_to_max_length=True,
|
| 17 |
+
truncation=True,
|
| 18 |
+
return_tensors="pt"
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
input_ids = inputs['input_ids']
|
| 22 |
+
attention_mask = inputs['attention_mask']
|
| 23 |
+
|
| 24 |
+
# Make prediction
|
| 25 |
+
model.eval() # Ensure the model is in evaluation mode
|
| 26 |
+
with torch.no_grad():
|
| 27 |
+
outputs = model(input_ids, attention_mask)
|
| 28 |
+
|
| 29 |
+
# Access the logits directly from the outputs Tensor
|
| 30 |
+
logits = outputs[0] # Assuming logits are the first element in the output tuple
|
| 31 |
+
|
| 32 |
+
# Get the prediction using argmax
|
| 33 |
+
prediction = torch.argmax(logits).item()
|
| 34 |
+
|
| 35 |
+
# Map prediction to label
|
| 36 |
+
label_map = {0: 'Real', 1: 'Fake'}
|
| 37 |
+
return label_map[prediction]
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
# Define a function to update on Twitter
|
| 42 |
+
def update_on_Twitter(tweet_text, prediction):
|
| 43 |
+
CONSUMER_KEY = "q76xzfaSG7jL4unpvaNuPM5Ms"
|
| 44 |
+
CONSUMER_SECRET = "7h2JCH9fveW3srWarhCmwLbr8rTtVeJ04Qo3q65VItX2L4eFs1"
|
| 45 |
+
ACCESS_TOKEN = "1636314191198932992-VesD9DTEnagO7fQdCiu5Fh6vuFLbw1"
|
| 46 |
+
ACCESS_TOKEN_SECRET = "DcTCYDGba8UWlbMEpDvmTMZuVI2XAip7Tu8QgLTrC12AW"
|
| 47 |
+
BAERER_TOKEN = "AAAAAAAAAAAAAAAAAAAAAPJjnwEAAAAA3DnqW09w51Oufv8UCReOPQLPUtA%3Dz9vzO4DXVbXRU63RZB3TzbCrBc0saEnQZ49GMmGkDqKVu30qwC"
|
| 48 |
+
|
| 49 |
+
# Authenticate to Twitter
|
| 50 |
+
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
|
| 51 |
+
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
|
| 52 |
+
|
| 53 |
+
# Create an API object
|
| 54 |
+
api = tweepy.API(auth)
|
| 55 |
+
|
| 56 |
+
# Create a Client object
|
| 57 |
+
client = tweepy.Client(
|
| 58 |
+
BAERER_TOKEN,
|
| 59 |
+
CONSUMER_KEY,
|
| 60 |
+
CONSUMER_SECRET,
|
| 61 |
+
ACCESS_TOKEN,
|
| 62 |
+
ACCESS_TOKEN_SECRET,
|
| 63 |
+
wait_on_rate_limit=True
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
postText = f"The news: {tweet_text} is {prediction}"
|
| 67 |
+
|
| 68 |
+
try:
|
| 69 |
+
api.verify_credentials()
|
| 70 |
+
print("Authentication OK")
|
| 71 |
+
client.create_tweet(text=postText)
|
| 72 |
+
return f'<a href="https://twitter.com/CANNBot" target="_blank">Detect Fake News on Twitter Bot Account</a>'
|
| 73 |
+
except Exception as e:
|
| 74 |
+
print(e)
|
| 75 |
+
return f'Error: {e}'
|
| 76 |
+
|
| 77 |
+
# Use Gradio Blocks to create a more flexible interface
|
| 78 |
+
with gr.Blocks() as demo:
|
| 79 |
+
gr.Markdown("# Fake News Detection")
|
| 80 |
+
text_input = gr.Textbox(placeholder="Enter a news Tweet here...", label="News Tweet")
|
| 81 |
+
text_output = gr.Textbox(label="Prediction")
|
| 82 |
+
link_output = gr.HTML(label="Twitter Bot Account")
|
| 83 |
+
|
| 84 |
+
# Button to get prediction
|
| 85 |
+
gr.Button("Predict").click(predict_fake_news, inputs=text_input, outputs=text_output)
|
| 86 |
+
|
| 87 |
+
# Button to generate a Gradio link
|
| 88 |
+
gr.Button("Detect on Twitter").click(update_on_Twitter, inputs=[text_input, text_output], outputs=link_output)
|
| 89 |
+
|
| 90 |
+
# Launch the interface
|
| 91 |
+
demo.launch()
|
c2_new_models2_weights.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:927a11b303b096af3e7ec34225a7efbc52f70e3c01490698ffba101378983185
|
| 3 |
+
size 439590589
|
requirements.txt
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
numpy
|
| 2 |
+
pandas
|
| 3 |
+
matplotlib.pyplot
|
| 4 |
+
pycaret
|
| 5 |
+
transformers
|
| 6 |
+
sklearn
|
| 7 |
+
torch
|
| 8 |
+
tensorflow
|
| 9 |
+
joblib
|
| 10 |
+
BertTokenizer
|
| 11 |
+
sklearn.model_selection
|
| 12 |
+
train_test_split
|
| 13 |
+
tensorflow.keras.preprocessing.text
|
| 14 |
+
Tokenizer
|
| 15 |
+
tensorflow.keras.preprocessing.sequence
|
| 16 |
+
pad_sequences
|
| 17 |
+
sklearn.metrics
|
| 18 |
+
accuracy_score
|
| 19 |
+
f1_score
|
| 20 |
+
recall_score
|
| 21 |
+
precision_score
|
| 22 |
+
confusion_matrix
|
| 23 |
+
seaborn
|
| 24 |
+
Sequential
|
| 25 |
+
Embedding
|
| 26 |
+
Dense
|
| 27 |
+
Dropout
|
| 28 |
+
Conv1D
|
| 29 |
+
MaxPooling1D
|
| 30 |
+
Flatten
|
| 31 |
+
gradio
|
| 32 |
+
tweepy
|