Giter Site home page Giter Site logo

fuzzy-dollop's Introduction

Smart Grid DApp

Overview

This decentralized application (DApp) leverages the power of federated learning and blockchain technology to enable secure and collaborative data analysis for smart grids.

Key Features

  • Federated Learning: Train a shared machine learning model across multiple smart grids without directly sharing raw data.
  • Differential Privacy: Enhance data privacy during model training using PySyft's DPAdam optimizer.
  • Homomorphic Encryption: Explore secure data aggregation techniques using homomorphic encryption.
  • Blockchain Integration: Record model updates and data usage agreements on the Energy Web Chain for transparency and auditability.

Technologies Used

  • PySyft: A framework for secure and private federated learning.
  • PyTorch: A deep learning library for model development.
  • Flask: A Python web framework for building the backend API.
  • Web3.py: A library for interacting with the Energy Web Chain.
  • Solidity: The programming language for writing the smart contract.
  • Truffle: A development environment for Ethereum and EVM-compatible blockchains.
  • Ganache: A local blockchain emulator for development and testing.

Project Structure

📦 fuzzy-dollop
├─ Dockerfile
├─ LICENSE
├─ app.py
├─ contracts
│  └─ DataSharing.sol
├─ docker-compose.yml
├─ federated_learning.py
├─ migrations
│  ├─ 1_initial_migration.js
│  └─ 2_deploy_contracts.js
├─ models
│  ├─ handler
│  │  └─ custom_handler.py
│  └─ model.py
├─ readme.md
├─ requirements.txt
├─ setup
│  ├─ setup_node.sh
│  ├─ setup_python.sh
│  └─ setup_torchserve.sh
├─ static
│  ├─ css
│  │  └─ styles.css
│  └─ js
│     └─ scripts.js
├─ templates
│  └─ index.html
├─ tests
│  ├─ test_blockchain.py
│  └─ test_prediction.py
└─ utils
   ├─ blockchain.py
   └─ prediction.py

Getting Started

Prerequisites

Installation

  1. Clone the Repository:

    git clone https://github.com/your-username/smart-grid-dapp.git
    cd smart-grid-dapp
    
  2. Install Dependencies:

Install Node.js dependencies

bash setup/setup_node.sh

Create a Python virtual environment and activate it

python3 -m venv venv source venv/bin/activate

Install Python dependencies

pip install -r requirements.txt

Install TorchServe

bash setup/setup_torchserve.sh

Configuration

Blockchain Configuration:

  1. Open truffle-config.js.
  2. Configure the networks section to connect to the Energy Web Chain.
  3. Provide your EWC account credentials and an API key for an EWC node provider (if necessary).

Private Key:

Important: Replace "YOUR_PRIVATE_KEY" in app.py and test_blockchain.py with a valid private key for interacting with the blockchain. For security reasons, use a test account and a testnet for development.

Running the Application

  1. Start Ganache (for local development):

    ganache-cli
  2. Deploy the Smart Contract:

    truffle compile
    truffle migrate --network ewc 
  3. Train the Model:

    python federated_learning.py
  4. Archive and Serve the Model:

    torch-model-archiver --model-name smartgridmodel --version 1.0 \
    --model-file models/model.py --serialized-file global_model.pth \
    --handler models/handler/custom_handler.py --export-path model_store
    
    torchserve --start --ncs --model-store model_store --models smartgridmodel=smartgridmodel.mar
  5. Run the Flask Application:

    python app.py
  6. Access the UI: Open the provided URL (from Codespaces or your local server) in your web browser.

Running Tests

  • Run All Tests:

    python -m unittest discover
  • Run Specific Tests:

    python -m unittest tests/test_blockchain.py
    python -m unittest tests/test_prediction.py

Future Work

  • Integrate real smart grid data sources.
  • Develop a more sophisticated user interface.
  • Implement additional blockchain functionalities (e.g., data usage agreements, tokenized rewards).
  • Explore more advanced privacy-preserving techniques.
  • Deploy to a production environment.

Contributing

Contributions are welcome! Please fork the repository and submit pull requests.

License

This project is licensed under the MIT License.

fuzzy-dollop's People

Contributors

sukanyamandal avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.