Skip to content

Rugvedrc/AI_captionGenerator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Creative Caption Generator

A Streamlit web application that generates creative captions for images using Google's Gemini AI model.

Features

  • 📸 Upload images (JPG, JPEG, PNG)
  • 🤖 AI-powered caption generation using Gemini 1.5 Flash
  • ✨ Generates 3 creative and short captions per image
  • 🖼️ Image preview before caption generation

Prerequisites

  • Python 3.7 or higher
  • Google Gemini API key

Installation

  1. Clone or download this repository

  2. Install required dependencies:

pip install streamlit google-generativeai pillow

Setup

  1. Get your Gemini API key:

  2. Configure your API key:

    Open the Python file and replace "YOUR_API_KEY" with your actual Gemini API key:

    genai.configure(api_key="your-actual-api-key-here")

    ⚠️ Security Note: For production use, store your API key in environment variables or a secure configuration file, not directly in the code.

Usage

  1. Run the application:
streamlit run app.py

(Replace app.py with your actual filename)

  1. Use the application:
    • Click "Browse files" to upload an image
    • Supported formats: JPG, JPEG, PNG
    • Click "Generate Captions" button
    • Wait for AI-generated captions to appear

Project Structure

├── app.py                 # Main application file
├── README.md             # This file
└── requirements.txt      # Python dependencies (optional)

Dependencies

streamlit
google-generativeai
pillow

You can create a requirements.txt file with these dependencies:

pip freeze > requirements.txt

How It Works

  1. User uploads an image through the Streamlit interface
  2. Image is displayed for preview
  3. When "Generate Captions" is clicked, the image and prompt are sent to Gemini AI
  4. Gemini 1.5 Flash model analyzes the image
  5. AI generates 3 creative, short captions
  6. Captions are displayed in the interface

Customization

You can modify the caption generation by changing the prompt in the code:

prompt = "Suggest 3 short and creative captions for a picture"

Examples of alternative prompts:

  • "Generate 5 funny captions for this image"
  • "Create poetic captions for this photo"
  • "Suggest Instagram-style captions with emojis"

Troubleshooting

Issue: API key error

  • Verify your API key is correct
  • Ensure you have API access enabled in Google AI Studio

Issue: Image won't upload

  • Check file format (must be JPG, JPEG, or PNG)
  • Ensure file size is reasonable (< 10MB recommended)

Issue: No captions generated

  • Check your internet connection
  • Verify API key has sufficient quota
  • Check the console for error messages

Limitations

  • Requires active internet connection
  • Subject to Gemini API rate limits and quotas
  • Image quality affects caption relevance

Future Enhancements

  • Support for multiple images
  • Caption style selection (funny, professional, poetic)
  • Download captions as text file
  • Caption editing and saving
  • Multi-language support

License

This project is open source and available for personal and educational use.

Acknowledgments

Support

For issues or questions:


About

Generates captions for images

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages