A robust REST API and interactive web interface for fake news detection using state-of-the-art machine learning models.
- Multiple ML Models: Choose from various pre-trained models:
- Logistic Regression (with text readability and sentiment features)
- Random Forest (using TF-IDF features)
- Naive Bayes (using TF-IDF features)
- REST API: Built with FastAPI for high performance and easy integration
- Interactive UI: User-friendly Streamlit interface for testing models
- Real-time Analysis: Get instant predictions with confidence scores
- Model Insights: View detailed model information and performance metrics
- Docker Support: Easy deployment with Docker containers
You can run the application either using Docker or directly on your machine.
-
Prerequisites
- Docker
- Docker Compose
-
Running the Application
# Clone the repository git clone https://github.com/ramcav/factos_api.git cd factos_api # Start the services docker-compose up -d # View logs (optional) docker-compose logs -f
The services will be available at:
- API: http://localhost:8002
- Streamlit UI: http://localhost:8501
-
Stopping the Application
docker-compose down
There are two ways to run the application locally: using command-line instructions or using the provided shell scripts.
-
Clone the repository
git clone https://github.com/ramcav/factos_api.git cd factos_api -
Set up and activate virtual environment
# Create virtual environments for both services # For API cd api python -m venv venv # Activate virtual environment # On Unix/macOS: source venv/bin/activate # On Windows: .\venv\Scripts\activate # Install API dependencies pip install -r requirements.txt # Start the API server uvicorn src.main:app --host 0.0.0.0 --port 8002 --reload
In a new terminal:
# For Streamlit app cd demo python -m venv venv # Activate virtual environment # On Unix/macOS: source venv/bin/activate # On Windows: .\venv\Scripts\activate # Install Streamlit app dependencies pip install -r requirements.txt # Start the Streamlit app streamlit run app.py
The services will be available at:
- API: http://localhost:8002
- Streamlit UI: http://localhost:8501
To deactivate the virtual environments when done:
deactivateThis will create a virtual environment, install dependencies and start the services.
-
Clone the repository
git clone https://github.com/ramcav/factos_api.git cd factos_api -
Make the scripts executable
chmod +x api/run.sh chmod +x demo/run.sh
-
Start the services
In the first terminal:
cd api ./run.shIn a second terminal:
cd demo ./run.sh
The services will be available at:
- API: http://localhost:8002
- Streamlit UI: http://localhost:8501
For both methods:
- Press
Ctrl+Cin each terminal to stop the services - If using virtual environments, run
deactivateto exit them
- Open the Streamlit interface in your browser
- Select a model from the sidebar
- Enter or paste the text you want to analyze
- Click "Analyze Text" to get the prediction
- View results including:
- Prediction (Fake/Real News)
- Confidence Score
- Model Details
- Full Analysis Results
The API provides the following endpoints:
GET /api/models
# List all available models
GET /api/models/{model_id}
# Get detailed information about a specific model
POST /api/models/{model_id}/predict
# Get prediction for input textExample API request:
curl -X POST "http://localhost:8002/api/models/1/predict" \
-H "Content-Type: application/json" \
-d '{"text": "Your news article text here"}'- API Layer: FastAPI for robust REST endpoints
- ML Models: Scikit-learn based models for text classification
- Frontend: Streamlit for interactive user interface
- Data Processing: NLTK for text preprocessing and feature extraction
The application supports the following environment variables:
API_URL: API endpoint URL (default: "http://localhost:8002")
| Model | Accuracy | Features |
|---|---|---|
| Logistic Regression | 73% | Text readability, sentiment |
| Random Forest | 99% | TF-IDF |
| Naive Bayes | 92% | TF-IDF |
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
- FastAPI for the amazing web framework
- Streamlit for the intuitive UI components
- Scikit-learn for machine learning tools
- NLTK for natural language processing capabilities