cassieli226/Gen_Motif
Gen-Motif: Interactive Motif Pattern Generator
Computationally extract, generate, and tessellate cultural design motifs into seamless tessellated patterns. Built with Gradio, Pillow, and custom vectorization tools for scalable pattern generation and export.
Overview
Gen-Motif is an AI-assisted design tool for generating, arranging, and exporting seamless ornamental patterns from cultural motif datasets. It combines a motif library, interactive canvas, and automated tessellation engine to help designers explore form, repetition, and vector structure.
Each session lets you:
- Select or drag motifs from a curated library.
- Generate a seamless tile and tessellated pattern preview.
- Export clean, scalable SVG or PNG outputs.
The resulting patterns preserve visual fidelity of raster motifs while enabling parametric reuse in fabrication workflows (e.g., laser cutting, CNC, or print).
Technical Workflow
The system runs a three-stage pipeline:
- Motif Sampling & Composition
- Users select motifs from the built-in library.
- Motifs are automatically stitched and mirrored into a square tile (
place_motifs_random_big,stitch_adjacent,strict_final_mirror).
- Tile Post-Processing
- The tile is cleaned and mirrored to ensure perfect edge continuity.
- The system densifies and crops it to a seamless boundary (
auto_tighten,densify_until,flatten_to_white).
- Raster → Vector Conversion
- The final tile is converted to SVG using custom
raster_to_svg()logic:
- Binarization and contour extraction (OpenCV).
- Small artifacts removed (
min_areafilter). - Paths simplified and exported via
svgwrite. - A tessellated SVG pattern is then generated (
_build_svg_tessellation).
Features
Example Outputs
(Previews above show PNG outputs)
File Outputs
How to Use
- Run the Space
- Open the app and wait for initialization.
- Select Motifs
- Drag motifs from the left library into the main canvas.
- Adjust Number of Motifs and Density sliders.
- Generate
- Click ✨ Generate Pattern to run the tessellation pipeline.
- Export
- Choose between PNG or SVG download formats.
- SVG output is fully vectorized for scalable fabrication workflows.
Dependencies
gradio>=4.0.0
datasets>=2.14.0
huggingface_hub>=0.20.0
pillow>=10.0.0
numpy>=1.23
python-multipart>=0.0.9
requests>=2.31.0
cairosvg>=2.7.0
opencv-python>=4.8.0
svgwrite>=1.4.3File Structure
app.py # Main Gradio interface
vectorize.py # PNG → SVG vectorization logic
svg_utils/ # Helpers for SVG building and tessellation
tmp_out/ # Temporary outputs
motif_samples/ # Source motif library
requirements.txt # Dependency list
README.md # You are hereAuthor
Cassie Li & Mary Zhang M.S. Computational Design @ Carnegie Mellon University
License
This project is released under the MIT License. Attribution is appreciated if used in research or derivative creative tools.
Short Description (for Space card)
Gen-Motif — an interactive AI tool that generates and vectorizes seamless patterns from cultural motifs. Drag motifs, adjust density, and export as clean SVGs or PNGs for creative and fabrication workflows.


