ByteBlaze's picture
Update app.py
a7ccda5 verified
raw
history blame
No virus
1.15 kB
import gradio as gr
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.feature_extraction.text import TfidfVectorizer
import joblib
# import warnings
# from sklearn.exceptions import InconsistentVersionWarning
# warnings.filterwarnings("ignore", category=InconsistentVersionWarning)
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):
features = vectorizer.transform(corpus).toarray()
prediction = nb_classifier.predict(features)
elif(choice == 2):
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)