File size: 1,672 Bytes
619fb86
5344de8
25842ad
00dd567
619fb86
25842ad
2e8a190
25842ad
851c9dd
5c96396
 
426fb1f
 
 
851c9dd
25842ad
619fb86
db17b18
25842ad
 
 
 
 
 
 
 
 
6f6379e
619fb86
00dd567
 
 
 
619fb86
00dd567
25842ad
554b7cc
00dd567
 
db17b18
554b7cc
00dd567
619fb86
 
 
 
74b882c
a7ccda5
74b882c
 
 
 
0b03db9
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
import gradio as gr
import nltk
from sklearn.feature_extraction.text import CountVectorizer 
from sklearn.feature_extraction.text import TfidfVectorizer
import joblib
from nltk.stem.porter import PorterStemmer
from nltk.corpus import stopwords
import re

nltk.download('stopwords')

# import warnings
# from sklearn.exceptions import InconsistentVersionWarning
# warnings.filterwarnings("ignore", category=InconsistentVersionWarning)

ps = PorterStemmer()

def preprocess_for_bow_and_tfidf(text):
    corpus = []
    text = re.sub('[^a-zA-Z0-9$£€¥%]',' ',text)
    text = text.lower()
    text = text.split()
    text = [ps.stem(t) for t in text if t not in stopwords.words('english')]
    corpus.append(' '.join(text))

    return corpus
    
vectorizer = joblib.load('./vectorizer.pkl')
nb_classifier = joblib.load('./nb_classifier.pkl')
tfidf_vectorizer = joblib.load('./tfidf_vectorizer.pkl')
random_forest = joblib.load('./random_forest.pkl')

def classify(text,choice):
  corpus=[text]
  if(choice == 1):
      corpus = preprocess_for_bow(text)
      features = vectorizer.transform(corpus).toarray()
      prediction = nb_classifier.predict(features)
  elif(choice == 2):
      corpus = preprocess_for_bow_and_tfidf
      features = tfidf_vectorizer.transform(corpus).toarray()
      prediction = random_forest.predict(features)
  if(prediction == 1):
     return "Fake News"
  else:
     return "Not Fake News"
GUI = gr.Interface(
    inputs = ['text', gr.Radio( choices = [("Naive Bayes",1) , ("Random Forest",2) ] , value = 1 , label = "Model") ],
    outputs = ['text'],
    fn = classify,
    title = "Fake News Detection System"
)
GUI.launch(debug = True)