File size: 752 Bytes
8ad4367
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import joblib

model = joblib.load("news_model.joblib")
vectorizer = joblib.load("news_vectorizer.joblib")

def predict_news(text):
    if not text.strip():
        return "Please enter some text"
    user_tfidf = vectorizer.transform([text])
    prediction = model.predict(user_tfidf)[0]
    proba = model.predict_proba(user_tfidf)[0]
    label = "REAL NEWS ✅" if prediction == 1 else "FAKE NEWS ❌"
    confidence = round(max(proba) * 100, 2)
    return f"{label} (Confidence: {confidence}%)"

iface = gr.Interface(
    fn=predict_news,
    inputs="text",
    outputs="text",
    title="Fake News Detector",
    description="Enter a news headline or short text and this AI will tell you if it's real or fake."
)

iface.launch()