CoolFace
Apppublic

ntairov/generativeai2

sourceHugging Faceupdated 10mo agoView on Hugging Face
0likes
App README

Voice to Image Agent

A Streamlit-based application that transforms voice messages into AI-generated images through a multi-step pipeline combining speech-to-text, natural language processing, and image generation.

Overview

This application takes a voice recording and converts it into a visual representation by:

  1. 1.Transcribing audio to text using OpenAI Whisper
  2. 2.Enhancing the transcript into a detailed image prompt using GPT-4
  3. 3.Generating an image from the prompt using DALL-E

The entire pipeline is transparent, showing intermediate results at each step.

Features

  • โ€”๐ŸŽ™๏ธ Audio Upload: Support for multiple formats (WAV, MP3, M4A, OGG, WebM)
  • โ€”๐Ÿ“ Speech-to-Text: Automatic transcription using Whisper
  • โ€”๐Ÿค– Prompt Enhancement: LLM-powered conversion of speech to detailed image descriptions
  • โ€”๐ŸŽจ Image Generation: High-quality image synthesis using DALL-E
  • โ€”๐Ÿ” Full Transparency: View transcripts, prompts, and metadata for each step
  • โ€”โš™๏ธ Configurable: Adjust models and parameters via the UI
  • โ€”๐Ÿ“Š Detailed Logging: Console logs for monitoring and debugging

Prerequisites

  • โ€”Python: 3.12 or higher
  • โ€”OpenAI API Key: Get one here
  • โ€”FFmpeg (optional): Required for certain audio formats (M4A, MP3)
  • โ€”Organization Verification (for gpt-image-1 model): Your OpenAI organization must be verified to use the gpt-image-1 image generation model. See Organization Verification section below.

Installation

1. Clone the Repository

bash
git clone <your-repo-url>
cd GenerativeAI2

2. Create Virtual Environment

bash
python3.12 -m venv .venv
source .venv/bin/activate  # On macOS/Linux
# .venv\Scripts\activate   # On Windows

3. Install Dependencies

bash
pip install -r requirements.txt

4. Configure API Key

Option A: Environment Variable

bash
export OPENAI_API_KEY="your-api-key-here"  # macOS/Linux

Option B: .env File (Recommended)

Create a .env file in the project root:

env
OPENAI_API_KEY=your-api-key-here

Usage

Start the Application

bash
streamlit run app.py

The app will open in your browser at http://localhost:8501

[image]

Workflow

  1. 1.Upload Audio: Click "Browse files" and select your voice recording
  2. 2.Configure Models (Optional): Adjust settings in the left sidebar
  3. 3.Transcription model (default: whisper-1)
  4. 4.LLM model (default: gpt-5-nano)
  5. 5.Image model (default: gpt-image-1)
  6. 6.Image size (512x512, 768x768, or 1024x1024)

[image]

  1. 1.Run Pipeline: Click "Run Voice โ†’ Image Pipeline"
  2. 2.View Results: See the transcript, enhanced prompt, and generated image

[image] [image]

Example Voice Prompts

  • โ€”"Create a futuristic city at sunset with flying cars and neon lights"
  • โ€”"Show me a peaceful forest with a waterfall and wildlife"
  • โ€”"Generate a portrait of a robot reading a book in a library"

Project Structure

GenerativeAI2/
โ”œโ”€โ”€ app.py                  # Streamlit UI and orchestration
โ”œโ”€โ”€ llm_pipeline.py         # Core pipeline functions
โ”œโ”€โ”€ requirements.txt        # Python dependencies
โ”œโ”€โ”€ README.md              # Documentation
โ”œโ”€โ”€ screenshots/            # UI screenshots
โ”‚   โ”œโ”€โ”€ UI_1.png           # Main interface
โ”‚   โ”œโ”€โ”€ UI_2.png           # Settings configuration
โ”‚   โ”œโ”€โ”€ UI_3.png           # Results display
โ”‚   โ””โ”€โ”€ UI_4.png           # Detailed results
โ””โ”€โ”€ .env                   # Environment variables (not in git)

Configuration

Model Selection

Configure models in the sidebar or modify defaults in the code:

python
# Default models in app.py
{
    "transcription_model": "whisper-1",
    "llm_model": "gpt-5-nano",
    "image_model": "gpt-image-1"
}

Image Sizes

Available sizes:

  • โ€”512x512 - Fast, lower cost
  • โ€”768x768 - Balanced
  • โ€”1024x1024 - High quality (default)

Logging

Logs are printed to the console where you run streamlit run app.py. Adjust log level:

python
# In app.py
logging.basicConfig(level=logging.INFO)  # Change to DEBUG for verbose output

Organization Verification

Important: The gpt-image-1 image generation model requires your OpenAI organization to be verified before use. This is a one-time setup process.

Verification Steps
  1. 1.Go to OpenAI Organization Settings
  2. 2.Click on "Verify Organization"
  3. 3.Complete the verification process (may require providing business/organization details)
  4. 4.Wait for access propagation: After verification, it can take up to 15 minutes for access to the gpt-image-1 model to become available
What to Expect
  • โ€”If you attempt to use gpt-image-1 before verification, you'll receive a PermissionDeniedError with error code 403
  • โ€”The error message will indicate that organization verification is required
  • โ€”After verification, wait 15 minutes before retrying image generation
  • โ€”If you need immediate access, consider using alternative image models like dall-e-3 (if available)
Alternative Models

If you need to use image generation immediately without waiting for verification, you can:

  • โ€”Switch to dall-e-3 model in the sidebar settings (if available for your account)
  • โ€”Or wait for the verification to complete and access to propagate

API Costs

Approximate costs per generation (as of 2024):

  • โ€”Whisper: ~$0.006 per minute of audio
  • โ€”GPT-4o-mini: ~$0.15 per 1M input tokens
  • โ€”DALL-E 3:
  • โ€”1024x1024: $0.040 per image
  • โ€”1024x1792 or 1792x1024: $0.080 per image

Architecture

Core Components

Frontend (`app.py`)

  • โ€”Streamlit UI for user interaction
  • โ€”Session state management
  • โ€”Error handling and display

Backend (`llm_pipeline.py`)

  • โ€”transcribe_audio(): Whisper API integration
  • โ€”build_image_prompt(): LLM prompt enhancement
  • โ€”generate_image(): DALL-E image generation

Pipeline Flow

Audio Upload โ†’ Transcription โ†’ Prompt Enhancement โ†’ Image Generation โ†’ Display
     โ†“              โ†“                  โ†“                    โ†“              โ†“
  User File    Whisper API         GPT API            DALL-E API      Results UI

Troubleshooting

Common Issues

"OPENAI_API_KEY environment variable is not set"

  • โ€”Ensure your .env file exists and contains the API key
  • โ€”Or export the environment variable in your terminal

"PermissionDeniedError: Your organization must be verified to use the model `gpt-image-1`"

  • โ€”This error occurs when trying to use gpt-image-1 without organization verification
  • โ€”Solution:
  • โ€”Visit OpenAI Organization Settings
  • โ€”Click "Verify Organization" and complete the verification process
  • โ€”Wait up to 15 minutes for access to propagate after verification
  • โ€”Retry the image generation after the waiting period
  • โ€”Alternative: Switch to dall-e-3 model in the sidebar if you need immediate access (if available for your account)

Audio format not supported

  • โ€”Install FFmpeg: brew install ffmpeg (macOS) or apt-get install ffmpeg (Linux)

Rate limit errors

  • โ€”Wait a few moments and try again
  • โ€”Check your OpenAI account usage limits

Module not found errors

  • โ€”Ensure virtual environment is activated
  • โ€”Reinstall dependencies: pip install -r requirements.txt

Development

Running Tests

bash
# Install test dependencies
pip install pytest pytest-mock

# Run tests
pytest

Code Style

This project follows PEP 8 guidelines. Format code with:

bash
pip install black
black app.py llm_pipeline.py

Limitations

  • โ€”Maximum audio file size: 25MB
  • โ€”Very long or noisy audio may produce less accurate transcripts
  • โ€”Generated images depend on prompt quality and model capabilities
  • โ€”No offline mode - requires internet connection for all operations

Security Notes

  • โ€”Never commit your .env file or API keys to version control
  • โ€”Add .env to .gitignore
  • โ€”Rotate API keys if accidentally exposed
  • โ€”Monitor API usage to prevent unexpected costs

Acknowledgments

  • โ€”OpenAI for Whisper, GPT, and DALL-E APIs
  • โ€”Streamlit for the web framework
  • โ€”Community contributors and testers