pocketflow/cookbook/pocketflow-streamlit-hitl/README.md

2.0 KiB

PocketFlow Streamlit Image Generation HITL

Human-in-the-Loop (HITL) image generation application using PocketFlow and Streamlit. Enter text prompts, generate images with OpenAI, and approve/regenerate results.

Features

  • Image Generation: Uses OpenAI's gpt-image-1 model to generate images from text prompts
  • Human Review: Interactive interface to approve or regenerate images
  • State Machine: Clean state-based workflow (initial_inputuser_feedbackfinal)
  • PocketFlow Integration: Uses PocketFlow Node and Flow for image generation with built-in retries
  • Session State Management: Streamlit session state acts as PocketFlow's shared store
  • In-Memory Images: Images stored as base64 strings, no disk storage required

How to Run

  1. Set OpenAI API Key:

    export OPENAI_API_KEY="your-openai-api-key"
    
  2. Install Dependencies:

    pip install -r requirements.txt
    
  3. Run the Streamlit Application:

    streamlit run app.py
    
  4. Access the Web UI: Open the URL provided by Streamlit (usually http://localhost:8501).

Usage

  1. Enter Prompt: Describe the image you want to generate
  2. Generate: Click "Generate Image" to create the image
  3. Review: View the generated image and choose:
    • Approve: Accept the image and move to final result
    • Regenerate: Generate a new image with the same prompt
  4. Final: View approved image and optionally start over

Files