This guide walks you through the process of building, reviewing, and publishing an app on Flower Hub.
It’s showtime—build your app! 🎉
You can refer to this example app for structure and best practices:
https://flower.ai/apps/yan-gao/example-app
Please follow the same README structure when creating your app.
Your app should run smoothly in both Simulation and Deployment without code changes. To achieve this, implement separate data loaders for each mode.
You can distinguish between Simulation and Deployment using context.node_config in ClientApp side. If ["partition-id", "num-partitions"] is present, the app is running in Simulation.
Here’s an example:
@app.train()
def train(msg: Message, context: Context):
"""Train the model on local data."""
# Load the data
batch_size = context.run_config["batch-size"]
if (
"partition-id" in context.node_config
and "num-partitions" in context.node_config
):
# **Simulation Engine**: use `flwr_datasets` and partition data on the fly
partition_id = context.node_config["partition-id"]
num_partitions = context.node_config["num-partitions"]
trainloader, _ = load_sim_data(partition_id, num_partitions, batch_size)
else:
# **Deployment Engine**: load demo data or real user data
data_path = context.node_config["data-path"]
trainloader, _ = load_local_data(data_path, batch_size)
# Training logic continues identically for both modes
Recommendations:
For Simulation, use flwr_datasets==0.6.0 for on-the-fly data partitioning: Flower Datasets Documentation
For Deployment, you may generate demo data using the CLI:
flwr-datasets create (see the instruction for details).
Once your app is ready:
flower/examples repository.