How pranjalg13/fake-news-detection works
Project Type and Purpose
• This project is a full-stack application with an emphasis on natural language processing tasks. The backend is built in Flask, offering two primary functionalities: detecting fake news (using an LSTM model) and clickbait (using a Multinomial Naive Bayes model).
• The README explains the models, dataset details, and the web GUI. The file tree shows the presence of frontend assets (HTML templates and CSS) and backend Python code (app.py, utils.py, and pre-trained models).
File Structure
• Key top-level files such as app.py indicate the Flask entry point.
• The templates directory holds the HTML files that form the web interface.
• The static directory contains CSS files used for styling the website.
• The trained_models folder stores serialized models (e.g., clickbait_model.pkl, final_h5_model.h5, vectorizer.pkl) used by the Flask backend during prediction.
• The colab_notebook directory contains exploratory/experimental notebooks documenting the model development process but is not part of the production system.
• The requirements.txt and other documentation files underscore the dependencies and guidelines for contribution.
Main Components
a. Frontend:
• Browser/User Interface: Represented by the HTML pages (index.html, clickbait.html, result.html, navbar.html).
• Static Assets: CSS stylesheets that improve the UI aesthetics.
b. Backend:
• Flask Application (app.py): Acts as the server managing routes for the home page, clickbait detection, and fake news detection.
• Utility Functions (utils.py): Contains helper methods to process input, handle predictions, and possibly pre/post-process data.
c. Machine Learning Models:
• Fake News Model: An LSTM model used to predict fake news based on the article content.
• Clickbait Model: A Multinomial Naive Bayes model chosen for its higher accuracy in clickbait detection.
• Model Artifacts: The pre-trained models and vectorizer files in the trained_models directory.
d. Data Flow Components:
• User Input: Text or news article submitted via the frontend.
• Data Preprocessing: Could be part of the utility functions (utils.py) that prepare the text for predictions.
• Prediction Engine: The backend that loads the models, applies them on user data, and returns a prediction.
• Results Response: The Flask application sends results back to the browser to be rendered using HTML templates.
Relationships and Interactions
• A user interacts with the system via a web browser, accessing the relevant HTML pages.
• The front end sends HTTP requests (via form submission or AJAX) to the Flask backend (app.py).
• The Flask application invokes utility functions which load the proper model from the trained_models directory and process the user’s input.
• After prediction, the Flask app sends the results back to the appropriate template (like result.html) for display.
• Additionally, the colab_notebook folder illustrates the experimental training processes for different models but is not part of live operations; you may optionally include an “Exploratory Analysis” note if needed.
Architectural Patterns and Technologies
• The application follows a Model-View-Controller-like split (even if not pure MVC, there is a clear separation between presentation (HTML/CSS) and business logic (Flask routes and ML models)).
• Use of Flask for web serving, along with Python’s machine learning libraries used to train and run the models.
• Distinction between frontend (user interface) and backend (API/prediction engine).