Joshua Yeung commited on
Commit
63cdf42
·
1 Parent(s): 037607b

Update smoke test, run script, and Makefile

Browse files

- smoke_test.py now uses GenerationResult and displays seed/LoRA status
- run.sh simplified with proper bash error handling
- Makefile cleaned up with standard phony targets

Files changed (3) hide show
  1. Makefile +3 -23
  2. run.sh +6 -34
  3. smoke_test.py +27 -86
Makefile CHANGED
@@ -1,33 +1,13 @@
1
- .PHONY: help install run test clean
2
-
3
- help:
4
- @echo ">� BrickStyle-Gen - Makefile Commands"
5
- @echo ""
6
- @echo " make install - Install dependencies"
7
- @echo " make run - Run the Gradio app"
8
- @echo " make test - Run smoke test"
9
- @echo " make clean - Clean generated files and cache"
10
- @echo ""
11
 
12
  install:
13
- @echo "=� Installing dependencies..."
14
  pip install -r requirements.txt
15
- @echo " Installation complete"
16
 
17
  run:
18
- @echo "=� Launching BrickStyle-Gen..."
19
- @echo " App will be available at: http://localhost:7860"
20
- @echo ""
21
  python app.py
22
 
23
- test:
24
- @echo ">� Running smoke test..."
25
  python smoke_test.py
26
 
27
  clean:
28
- @echo ">� Cleaning up..."
29
- rm -rf __pycache__ pipelines/__pycache__ research/__pycache__
30
- rm -rf out/*.png out/*.jpg
31
- rm -rf .pytest_cache
32
- rm -rf *.pyc
33
- @echo " Cleanup complete"
 
1
+ .PHONY: install run smoke clean
 
 
 
 
 
 
 
 
 
2
 
3
  install:
 
4
  pip install -r requirements.txt
 
5
 
6
  run:
 
 
 
7
  python app.py
8
 
9
+ smoke:
 
10
  python smoke_test.py
11
 
12
  clean:
13
+ rm -rf __pycache__ */__pycache__ .pytest_cache out/smoke.png
 
 
 
 
 
run.sh CHANGED
@@ -1,39 +1,11 @@
1
- #!/bin/bash
2
- # BrickStyle-Gen Launcher Script
3
 
4
- set -e
5
-
6
- echo ">� BrickStyle-Gen Launcher"
7
- echo "=========================="
8
- echo ""
9
-
10
- # Check if virtual environment exists
11
- if [ ! -d "venv" ]; then
12
- echo "Virtual environment not found. Creating..."
13
- python3 -m venv venv
14
- echo " Virtual environment created"
15
- fi
16
-
17
- # Activate virtual environment
18
- echo "Activating virtual environment..."
19
- source venv/bin/activate
20
-
21
- # Check if dependencies are installed
22
- if ! python -c "import gradio" 2>/dev/null; then
23
- echo "Dependencies not installed. Installing..."
24
- pip install -r requirements.txt
25
- echo " Dependencies installed"
26
  fi
27
 
28
- # Create output directory
29
- mkdir -p out
30
-
31
- # Launch app
32
- echo ""
33
- echo "=� Launching BrickStyle-Gen..."
34
- echo " App will be available at: http://localhost:7860"
35
- echo ""
36
- echo " Press Ctrl+C to stop"
37
- echo ""
38
 
39
  python app.py
 
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
 
4
+ if [[ -f ".venv/bin/activate" ]]; then
5
+ source .venv/bin/activate
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  fi
7
 
8
+ export GRADIO_SERVER_NAME=${GRADIO_SERVER_NAME:-0.0.0.0}
9
+ export GRADIO_SERVER_PORT=${GRADIO_SERVER_PORT:-7860}
 
 
 
 
 
 
 
 
10
 
11
  python app.py
smoke_test.py CHANGED
@@ -1,99 +1,40 @@
1
- #!/usr/bin/env python3
2
- """
3
- Smoke Test for BrickStyle-Gen
4
- Quick validation that the pipeline can generate images.
5
 
6
- Usage:
7
- python smoke_test.py
8
-
9
- This will:
10
- 1. Load the SDXL + LoRA model
11
- 2. Generate one 768x768 test image
12
- 3. Save to out/smoke_test.png
13
- 4. Report timing and success/failure
14
- """
15
-
16
- import os
17
- import time
18
  from pathlib import Path
19
 
20
- print("=" * 60)
21
- print(">� BrickStyle-Gen Smoke Test")
22
- print("=" * 60)
23
- print()
24
 
25
- # Create output directory
26
- out_dir = Path("out")
27
- out_dir.mkdir(exist_ok=True)
28
 
29
- print("Step 1/3: Importing dependencies...")
30
- try:
31
- from pipelines.sdxl_lego_lora import load_model
32
- import torch
33
- print(f"  PyTorch {torch.__version__}")
34
- print(f"  Device available: {torch.cuda.is_available() and 'CUDA' or torch.backends.mps.is_available() and 'MPS' or 'CPU'}")
35
- except ImportError as e:
36
- print(f" L Import failed: {e}")
37
- print("\n Please install dependencies:")
38
- print(" pip install -r requirements.txt")
39
- exit(1)
40
 
41
- print()
42
- print("Step 2/3: Loading model (this may take a few minutes on first run)...")
43
- start_load = time.time()
44
- try:
45
  generator = load_model()
46
- load_time = time.time() - start_load
47
- print(f"  Model loaded in {load_time:.1f}s")
48
- except Exception as e:
49
- print(f" L Model loading failed: {e}")
50
- exit(1)
51
-
52
- print()
53
- print("Step 3/3: Generating test image...")
54
- print(" Prompt: 'a tiny brick castle on a hill'")
55
- print(" Settings: 768x768, 25 steps, seed=42")
56
- print()
57
-
58
- start_gen = time.time()
59
- try:
60
- images = generator.generate(
61
- prompt="a tiny brick castle on a hill",
62
- negative_prompt="text, watermark, deformed",
63
- num_inference_steps=25,
64
- guidance_scale=7.5,
65
- seed=42,
66
- width=768,
67
- height=768,
68
  batch_size=1,
 
69
  )
70
 
71
- gen_time = time.time() - start_gen
72
-
73
- # Save image
74
- output_path = out_dir / "smoke_test.png"
75
- images[0].save(output_path)
76
 
77
- print(f"  Generation complete in {gen_time:.1f}s")
78
- print(f"  Image saved to: {output_path}")
 
 
 
 
79
 
80
- except Exception as e:
81
- print(f" L Generation failed: {e}")
82
- import traceback
83
- traceback.print_exc()
84
- exit(1)
85
 
86
- print()
87
- print("=" * 60)
88
- print(" SMOKE TEST PASSED")
89
- print("=" * 60)
90
- print()
91
- print(f"Total time: {time.time() - start_load:.1f}s")
92
- print(f"Model load: {load_time:.1f}s")
93
- print(f"Generation: {gen_time:.1f}s")
94
- print()
95
- print("Next steps:")
96
- print(" 1. Open out/smoke_test.png to verify brick-style")
97
- print(" 2. Run the full app: python app.py")
98
- print(" 3. Visit http://localhost:7860")
99
- print()
 
1
+ """Minimal smoke test for the BrickStyle-Gen text pipeline."""
 
 
 
2
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  from pathlib import Path
4
 
5
+ from pipelines.sdxl_lego_lora import load_model
 
 
 
6
 
 
 
 
7
 
8
+ def main() -> None:
9
+ print("=" * 60)
10
+ print("BrickStyle-Gen Smoke Test")
11
+ print("=" * 60)
12
+ print()
 
 
 
 
 
 
13
 
 
 
 
 
14
  generator = load_model()
15
+ result = generator.generate(
16
+ prompt="brick-style micro city skyline, studs visible",
17
+ negative_prompt="text, watermark, logo",
18
+ num_inference_steps=10,
19
+ guidance_scale=7.0,
20
+ width=512,
21
+ height=512,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  batch_size=1,
23
+ lora_scale=1.0,
24
  )
25
 
26
+ out_dir = Path("out")
27
+ out_dir.mkdir(exist_ok=True)
28
+ output_path = out_dir / "smoke.png"
29
+ result.images[0].save(output_path)
 
30
 
31
+ print()
32
+ print("=" * 60)
33
+ print(f"Smoke test image saved to {output_path}")
34
+ print(f"Seed: {result.seed}")
35
+ print(f"LoRA applied: {result.lora_applied}")
36
+ print("=" * 60)
37
 
 
 
 
 
 
38
 
39
+ if __name__ == "__main__":
40
+ main()