Skip to content

svanalex/HaikusFromPaintings

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HaikusFromPaintings

HAIKU Logo

Python Flask LLM License

Description

HAIKU is a multimodal, AI-driven poetry system that generates emotionally resonant haikus inspired by visual art and the current emotional climate of the world. It combines news-based mood detection, image understanding, and creative language generation to simulate computational creativity.

Features

  • News-Based Emotion Modeling: Analyzes recent news articles to determine a dominant emotional state using an LLM-based classifier and a psychologically-informed emotion model (VAD).
  • Image-Driven Inspiration: Extracts salient features (colors, descriptive image caption) from uploaded images using vision-language models.
  • Dynamic Prompt Engineering: Dynamically generates poetic prompts using five distinct strategies tailored to the image and emotional context.
  • LLM-Generated Poetry: Crafts multiple haikus using LLMs and selects the best one based on structural and aesthetic evaluation.
  • Narrative Explanations: Provides readable emotional narratives showing how the mood was shaped and why a haiku was selected.
  • Web Interface: A clean, intuitive GUI where users can run the system on example images or upload their own.

Installation & Setup

  1. Clone the repository
git clone https://github.com/svanalex/HaikusFromPaintings.git
cd HaikusFromPaintings
  1. Create a virtual environment
python -m venv venv
  1. Activate the environemnt On macOS/Linux:
source venv/bin/activate        

On Windows:

venv\Scripts\activate 
  1. Install Python dependencies
pip install -r requirements.txt
  1. Set up your API keys

This project requires access to a news API (e.g., NewsAPI.org) and an LLM backend (e.g., Groq). To claim your API keys, please follow the instructions on the respective sources:

  1. Set up the .env file

In the root directory of the project, create a file named .env:

# You can do this manually or using the terminal
touch .env # for macOS/Linux
New-Item -Path . -Name ".env" -ItemType "File" # for Windows

Paste the following as the content of your .env file (using your real API keys from Step 5):

# .env (Do NOT commit this file!)
NEWS_API_KEY=your_news_api_key_here
GROQ_API_KEY=your_groq_api_key_here
LLAMA_MODEL_ID=meta-llama/llama-4-scout-17b-16e-instruct # we used this version of llama but you can try different ones
  1. Run the app
python app.py

Open your browser and go to: http://127.0.0.1:5000

How to Use

  1. Open the app in your browser
  2. Click "Run with Example Image" to see how the system works on a predefined image
  3. Upload a custom image and click "Run with Uploaded Image" to create a unique haiku for it

Project Structure

components/ – Modular system components

  • emotion_engine/ – Handles emotional profiling and mood generation using news articles and personality profiles (GoEmotions, VAD scoring, personality weightings).
  • evaluator/ – Evaluates haikus based on structure, emotion alignment, and poetic quality.
  • haiku_generator/ – Interfaces with an LLM (e.g., LLaMA via Groq) to generate haikus from prompts.
  • image_analysis/ – Runs BLIP captioning and color palette extraction on the image.
  • prompt_engineering/ – Creates multiple types of prompts (instructional, contextual, role-based, etc.) for haiku generation.

core/

  • haiku_orchestrator.py – Central orchestrator script that runs the full haiku generation pipeline, combining emotion, image, prompt, and haiku logic.

exploratory_notebooks/

  • Archived and experimental notebooks and scripts for reference and testing purposes.

static/

  • Publicly served static assets:
    • styles.css – Custom styling for frontend.
    • example.jpg, uploads/ – Image assets and user uploads (uploads should be .gitignored).

templates/

  • index.html – Main frontend HTML template rendered with Jinja2 via Flask. Displays input, haikus, emotion summaries, and image analysis results.

Other Root Files

  • .gitignore – Excludes .env, uploads/, virtual environments, etc.
  • app.py – Flask app entry point and route logic.
  • requirements.txt – Lists all Python dependencies.

Notes

The system is modular: You can swap out models or APIs with minimal changes.

Currently optimized for educational and experimental use - not for production deployment.

Credits

Built in Spring 2025 by Alexander Svancara, Andreas Kramer, and Courtney Bodily for the course Advanced Computational Creativity, taught by Paul Bodily, Ph.D at Idaho State University.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •