fake-news / app.py
Last commit not found
raw
history blame
1.12 kB
import gradio as gr
import lightgbm as lgb
import joblib
# Load your trained model (assuming it's saved as 'lgbm_model.pkl')
model = joblib.load('lgbm_model.pkl')
def classify_text(text):
# Convert the input text to the appropriate format for your model
# For simplicity, let's assume you have a function `preprocess_text` for this
# processed_text = preprocess_text(text)
# If your model expects numerical features, convert text to numerical features
# For example:
# features = text_to_features(processed_text)
# Here, we assume the model can take raw text directly for simplicity
prediction = model.predict([text])
return int(prediction[0])
# Create the Gradio interface
iface = gr.Interface(
fn=classify_text,
inputs=gr.inputs.Textbox(lines=2, placeholder="Enter text here..."),
outputs=gr.outputs.Label(num_top_classes=1),
title="Fake News Classifier",
description="Enter text to classify if it's fake (1) or not fake (0).",
examples=["This is a sample news article."]
)
# Launch the interface
if __name__ == "__main__":
iface.launch()