Skip to content
/ haikoo Public

Haiku generator -- generates a haiku poem from an image!

Notifications You must be signed in to change notification settings

robu3/haikoo

Repository files navigation

haikoo 🖋

日本語はこちら

Haikoo is a fun little haiku generator. It uses Azure Congnitive Services, Markov chains (leveraging Markovify), and word syllable counts to create haiku from an image. The text is then overlaid on a cropped version of the original picture to create a consolidated image ready for social media.

Given an image like this:

Input

It produces something like this:

Output

Basic Usage

Haikoo can be used as module or as a command line utility.

As a module:

from haikoo.haikoo import Haikoo, ImageDescriber

# instantiate image describer and haikoo
# the markov model can be: fusion (recommended), shakespeare, frost, or classic
describer = ImageDescriber("azure_cv_key", "azure_cv_region")
haikoo = Haikoo(describer, "fusion")

# then create your haiku!
haiku = haikoo.create_image(file_path=args.image, out_file_path=args.out, text=args.text)

From the terminal:

python app.py /path/to/image.png

When using the terminal application, you will need to copy config.json.default to config.json and update the file with your Azure CV key and region before beginning. Let the programmatically generated poetry begin!

Technical Details

Haikoo extends/subclasses a couple of Markovify's classes in order to create Markov chain models that also take syllable count into consideration when selecting words, i.e., HaikuChain and HaikuText. HaikuChain counts the number of syllables in a word when tokenizing text; the result can be serialized for reuse later, negating the need to count syllables at runtime (a performance win).

Advanced Usage

The Azure Computer Vision-based ImageDescriber can swapped out with another implementation by passing it into the constructor; see the MockImageDescriber for an example.

from haikoo.haikoo import Haikoo, MyCustomImageDescriber

describer = MyCustomImageDescriber()
haikoo = Haikoo(describer, "fusion")

日本語版

haikoo 🖋

「Haikoo」というのは楽しい俳句ジェネレータです。Azure Congnitive Services、 マルコフ連鎖 (Markovifyを生かして)、 と言葉の音節数を使って絵から俳句を作ります。その俳句は元の絵の上に重なって出来上がり、ソーシャルメディアにもピッタリ!

こういう絵にすれば:

Input

こんなんが出て来る:

Output

基本の使い方

「Haikoo」はモジュールかコマンドライン・インタフェースとして使えます。

モジュールとして:

from haikoo.haikoo import Haikoo, ImageDescriber

# instantiate image describer and haikoo
# the markov model can be: fusion (recommended), shakespeare, frost, or classic
describer = ImageDescriber("azure_cv_key", "azure_cv_region")
haikoo = Haikoo(describer, "fusion")

# then create your haiku!
haiku = haikoo.create_image(file_path=args.image, out_file_path=args.out, text=args.text)

CLIとして:

python app.py /path/to/image.png

コマンドライン・インタフェースを使う時は始める前にconfig.json.defaultconfig.jsonにコピーして、Azureのキーと地域を更新しなければなりません。

さぁ、俳句ジェネレータ開始!

技術詳細

「Haikoo」は言葉の選ばれる時に音節数を考えるマルコフ連鎖を作るため、Markovifyのクラスを建て増します。例えば、HaikuChainHaikuTextHaikuChainはトークン化しながら音節数を数え、その結果はシリアライズする事も可能。ランタイムにしなくてもいいので性能アップ!

高度な使い方

「Azure Computer Vision」に基づいているImage Describerは他のインプリメンテーションをコンストラクタに入れて変えられます。例についてはMockImageDescriberを参照してください。

from haikoo.haikoo import Haikoo, MyCustomImageDescriber

describer = MyCustomImageDescriber()
haikoo = Haikoo(describer, "fusion")

About

Haiku generator -- generates a haiku poem from an image!

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages