saadbather commited on
Commit
ee60155
·
verified ·
1 Parent(s): 7f181ec

Add synthetic Flower demo wrapper

Browse files
Files changed (1) hide show
  1. demo.py +38 -0
demo.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Run the small SwarmFL Flower demo from the Hugging Face Hub."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import argparse
6
+ import json
7
+ import shutil
8
+ import subprocess
9
+ import sys
10
+ from pathlib import Path
11
+
12
+
13
+ def main() -> None:
14
+ parser = argparse.ArgumentParser(description="Run the SwarmFL synthetic Flower demo")
15
+ parser.add_argument("--output", type=Path, default=Path("swarmfl-demo"))
16
+ parser.add_argument("--feedback", action="store_true")
17
+ args = parser.parse_args()
18
+
19
+ command = shutil.which("swarmfl-quickstart")
20
+ if command is None:
21
+ raise SystemExit("Install first: pip install swarmfl==0.1.0")
22
+ if args.output.exists():
23
+ raise SystemExit(f"Output already exists: {args.output}; choose another --output")
24
+
25
+ cmd = [command, "--output", str(args.output)]
26
+ if args.feedback:
27
+ cmd.append("--feedback")
28
+ subprocess.run(cmd, check=True)
29
+ result = json.loads((args.output / "result.json").read_text(encoding="utf-8"))
30
+ print(json.dumps({
31
+ "flower_clients": result.get("flower_clients"),
32
+ "predictions": len(result.get("predictions", [])),
33
+ "output": str(args.output),
34
+ }, indent=2))
35
+
36
+
37
+ if __name__ == "__main__":
38
+ main()