File size: 1,238 Bytes
7cca5b0
7c6e40f
 
7cca5b0
8ee79a3
 
7cca5b0
8ee79a3
 
 
7cca5b0
7c6e40f
8ee79a3
 
7cca5b0
8ee79a3
7cca5b0
 
8ee79a3
7c6e40f
8ee79a3
 
7cca5b0
8ee79a3
 
 
7c6e40f
 
8ee79a3
7cca5b0
8ee79a3
 
7cca5b0
8ee79a3
 
7cca5b0
8ee79a3
7cca5b0
 
8ee79a3
 
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
import gradio as gr
import pickle
import string
import nltk
from nltk.corpus import stopwords
from nltk.stem.porter import PorterStemmer

nltk.download('stopwords')
ps = PorterStemmer()
stop_words = set(stopwords.words('english'))

# Load model and vectorizer
model = pickle.load(open("model.pkl", "rb"))
vectorizer = pickle.load(open("vectorizer.pkl", "rb"))

# Text cleaning function
def clean_text(text):
    text = text.lower()
    text = ''.join([char for char in text if char not in string.punctuation])
    tokens = text.split()
    filtered = [ps.stem(word) for word in tokens if word not in stop_words]
    return " ".join(filtered)

# Prediction function
def predict_news(news):
    cleaned = clean_text(news)
    vectorized = vectorizer.transform([cleaned])
    prediction = model.predict(vectorized)[0]
    return "πŸ”΄ Fake News" if prediction == 0 else "🟒 Real News"

# Gradio UI
interface = gr.Interface(
    fn=predict_news,
    inputs=gr.Textbox(lines=7, placeholder="Enter news text here..."),
    outputs=gr.Textbox(label="Prediction"),
    title="πŸ“° Fake News Detector",
    description="Enter a news article and detect if it's real or fake using NLP and ML."
)

if __name__ == "__main__":
    interface.launch()