Giter Site home page Giter Site logo

haikoo's Introduction

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")

haikoo's People

Contributors

dependabot[bot] avatar robu3 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.