A Streamlit web application that generates creative captions for images using Google's Gemini AI model.
- 📸 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
- Python 3.7 or higher
- Google Gemini API key
-
Clone or download this repository
-
Install required dependencies:
pip install streamlit google-generativeai pillow-
Get your Gemini API key:
- Visit Google AI Studio
- Sign in with your Google account
- Create a new API key
-
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.
- Run the application:
streamlit run app.py(Replace app.py with your actual filename)
- 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
├── app.py # Main application file
├── README.md # This file
└── requirements.txt # Python dependencies (optional)
streamlit
google-generativeai
pillow
You can create a requirements.txt file with these dependencies:
pip freeze > requirements.txt- User uploads an image through the Streamlit interface
- Image is displayed for preview
- When "Generate Captions" is clicked, the image and prompt are sent to Gemini AI
- Gemini 1.5 Flash model analyzes the image
- AI generates 3 creative, short captions
- Captions are displayed in the interface
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"
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
- Requires active internet connection
- Subject to Gemini API rate limits and quotas
- Image quality affects caption relevance
- Support for multiple images
- Caption style selection (funny, professional, poetic)
- Download captions as text file
- Caption editing and saving
- Multi-language support
This project is open source and available for personal and educational use.
- Built with Streamlit
- Powered by Google Gemini AI
For issues or questions:
- Check the Streamlit documentation
- Review Gemini API documentation
- File an issue in the repository