Spaces:
Sleeping
Sleeping
title: Federated Credit Scoring | |
emoji: π | |
colorFrom: red | |
colorTo: red | |
sdk: streamlit | |
app_port: 8501 | |
tags: | |
- streamlit | |
- federated-learning | |
- machine-learning | |
- privacy | |
pinned: false | |
short_description: Federated Learning Credit Scoring Demo | |
license: mit | |
# Federated Learning for Privacy-Preserving Financial Data Generation with RAG Integration | |
This project implements a complete federated learning framework with a Retrieval-Augmented Generation (RAG) system for privacy-preserving synthetic financial data generation. The system includes a working server, multiple clients, and an interactive web application. | |
## Live Demo | |
**Try it now**: [Hugging Face Spaces](https://huggingface.co/spaces/ArchCoder/federated-credit-scoring) | |
## Features | |
- **Complete Federated Learning System**: Working server, clients, and web interface | |
- **Real-time Predictions**: Get credit score predictions from the federated model | |
- **Interactive Web App**: Beautiful Streamlit interface with demo and real modes | |
- **Client Simulator**: Built-in client simulator for testing | |
- **Privacy-Preserving**: No raw data sharing between participants | |
- **Educational**: Learn about federated learning concepts | |
- **Production Ready**: Docker and Kubernetes deployment support | |
## Quick Start | |
### Option 1: Try the Demo | |
1. Visit the [Live Demo](https://huggingface.co/spaces/ArchCoder/federated-credit-scoring) | |
2. Enter customer features and get predictions | |
3. Learn about federated learning | |
### Option 2: Run Locally (Complete System) | |
1. **Install Dependencies** | |
```bash | |
# Create virtual environment | |
python3 -m venv venv | |
source venv/bin/activate # On Windows: venv\Scripts\activate | |
# Install dependencies | |
pip install -r requirements-full.txt | |
``` | |
2. **Start the Federated Server** | |
```bash | |
python -m src.main --mode server --config config/server_config.yaml | |
``` | |
3. **Start Multiple Clients** (in separate terminals) | |
```bash | |
python -m src.main --mode client --config config/client_config.yaml | |
``` | |
4. **Run the Web Application** | |
```bash | |
streamlit run webapp/streamlit_app.py | |
``` | |
5. **Test the Complete System** | |
```bash | |
python test_complete_system.py | |
``` | |
## How to Use | |
### Web Application Features: | |
- **Demo Mode**: Works without server (perfect for HF Spaces) | |
- **Real Mode**: Connects to federated server for live predictions | |
- **Client Simulator**: Start/stop client participation | |
- **Training Progress**: Real-time monitoring of federated rounds | |
- **Server Health**: Check server status and metrics | |
- **Educational Content**: Learn about federated learning | |
### Federated Learning Process: | |
1. **Server Initialization**: Global model is created | |
2. **Client Registration**: Banks register with the server | |
3. **Local Training**: Each client trains on their local data | |
4. **Model Updates**: Clients send model updates (not data) to server | |
5. **Aggregation**: Server aggregates updates using FedAvg | |
6. **Global Model**: Updated model is distributed to all clients | |
7. **Prediction**: Users can get predictions from the global model | |
## System Architecture | |
``` | |
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ | |
β Web App β β Federated β β Client 1 β | |
β (Streamlit) βββββΊβ Server βββββΊβ (Bank A) β | |
β β β (Coordinator) β β β | |
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ | |
β | |
βΌ | |
βββββββββββββββββββ | |
β Client 2 β | |
β (Bank B) β | |
βββββββββββββββββββ | |
``` | |
## Project Structure | |
``` | |
FinFedRAG-Financial-Federated-RAG/ | |
βββ src/ | |
β βββ api/ # REST API for server and client communication | |
β βββ client/ # Federated learning client implementation | |
β βββ server/ # Federated learning server and coordinator | |
β βββ rag/ # Retrieval-Augmented Generation components | |
β βββ models/ # VAE/GAN models for data generation | |
β βββ utils/ # Privacy, metrics, and utility functions | |
βββ webapp/ # Streamlit web application | |
βββ config/ # Configuration files | |
βββ tests/ # Unit and integration tests | |
βββ docker/ # Docker configurations | |
βββ kubernetes/ # Kubernetes deployment files | |
βββ app.py # Root app.py for Hugging Face Spaces deployment | |
βββ requirements.txt # Minimal dependencies for HF Spaces | |
βββ requirements-full.txt # Complete dependencies for local development | |
βββ test_complete_system.py # End-to-end system test | |
``` | |
## Configuration | |
### Server Configuration (`config/server_config.yaml`) | |
```yaml | |
# API server configuration | |
api: | |
host: "0.0.0.0" | |
port: 8080 | |
# Federated learning configuration | |
federated: | |
min_clients: 2 | |
rounds: 10 | |
# Model configuration | |
model: | |
input_dim: 32 | |
hidden_layers: [128, 64] | |
``` | |
### Client Configuration (`config/client_config.yaml`) | |
```yaml | |
client: | |
id: "client_1" | |
server_url: "http://localhost:8080" | |
data: | |
batch_size: 32 | |
input_dim: 32 | |
``` | |
## Testing | |
Run the complete system test: | |
```bash | |
python test_complete_system.py | |
``` | |
This will test: | |
- Server health | |
- Client registration | |
- Training status | |
- Prediction functionality | |
## Deployment | |
### Hugging Face Spaces (Recommended) | |
1. Fork this repository | |
2. Create a new Space on HF | |
3. Connect your repository | |
4. Deploy automatically | |
### Local Development | |
```bash | |
# Install full dependencies | |
pip install -r requirements-full.txt | |
# Run complete system | |
python -m src.main --mode server --config config/server_config.yaml & | |
python -m src.main --mode client --config config/client_config.yaml & | |
streamlit run webapp/streamlit_app.py | |
``` | |
### Docker Deployment | |
```bash | |
docker-compose up | |
``` | |
## Performance | |
- **Model Accuracy**: 85%+ across federated rounds | |
- **Response Time**: <1 second for predictions | |
- **Scalability**: Supports 10+ concurrent clients | |
- **Privacy**: Zero raw data sharing | |
## Contributing | |
1. Fork the repository | |
2. Create a feature branch | |
3. Make your changes | |
4. Add tests | |
5. Submit a pull request | |
## License | |
MIT License - see LICENSE file for details. | |
## Acknowledgments | |
- TensorFlow for the ML framework | |
- Streamlit for the web interface | |
- Hugging Face for hosting the demo | |
--- | |
**Live Demo**: https://huggingface.co/spaces/ArchCoder/federated-credit-scoring | |