File size: 1,271 Bytes
0845268 056fb47 0845268 |
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 numpy as np
import pandas as pd
from keras.preprocessing.sequence import pad_sequences
from keras.models import load_model
from tensorflow.keras.preprocessing.text import Tokenizer
# Load the dataset
df = pd.read_csv("bangla_english_fake.csv") # Update the filename with your dataset
# Preprocess the data
max_len = 1600
tokenizer = Tokenizer()
tokenizer.fit_on_texts(df["text"])
text_seq = tokenizer.texts_to_sequences(df["text"])
# Load the LSTM model
model = load_model("bangla_english_fake_model.h5")
# Define function for fake news detection
def classify_fake_news(text):
# Tokenize and pad the input text sequence
text_sequence = tokenizer.texts_to_sequences([text])
padded_sequence = pad_sequences(text_sequence, maxlen=max_len)
# Predict the label for the input text
prediction = model.predict(padded_sequence)[0]
# Convert prediction to label
label = "Fake" if prediction < 0.5 else "Real"
return label
# Define Gradio interface
iface = gr.Interface(
fn=classify_fake_news,
inputs="text",
outputs="label",
title="Bangla & English Fake News Detection",
description="Enter a news article to detect if it's fake or real."
)
# Launch the Gradio interface
iface.launch(share=True)
|