CoolFace
Apppublic

cassieli226/Gen_Motif

sourceHugging Facemitupdated 1mo agoView on Hugging Face
0likes
App README

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:

  1. 1.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).
  1. 1.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).
  1. 1.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_area filter).
  • Paths simplified and exported via svgwrite.
  • A tessellated SVG pattern is then generated (_build_svg_tessellation).

Features

FeatureDescription
Interactive CanvasDrag motifs to compose your base tile.
Dynamic TessellationPreview infinite patterns based on your tile.
Adjustable ParametersNumber of motifs and density control pattern complexity.
PNG & SVG ExportsChoose raster output for preview or vector output for fabrication.
Smart Vector CleaningAutomatically removes tiny noise and smooths contours.
Half-Drop ModeCreates alternating offset tessellation for visual variation.

Example Outputs

StagePreview
Motif Tile
Tessellated Pattern

(Previews above show PNG outputs)


File Outputs

FileDescription
seamless_tile_[uid].pngPost-processed single motif tile (for reference).
pattern_[uid].pngLarge raster preview of the tessellated pattern.
seamless_tile_[uid].svgVector version of the seamless tile (contours only).
pattern_[uid].svgVector tessellation built from the tile SVG.

How to Use

  1. 1.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.3

File 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 here

Author

Cassie Li & Mary Zhang M.S. Computational Design @ Carnegie Mellon University

Hugging Face Profile


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.