├── requirements.txt ├── LICENSE ├── README.md └── app.py /requirements.txt: -------------------------------------------------------------------------------- 1 | streamlit==1.21.0 2 | google-generativeai==0.1.1 3 | Pillow==10.0.0 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Rugvedrc 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Creative Caption Generator 2 | 3 | A Streamlit application that generates creative captions for uploaded images using Google Generative AI. Users can upload an image, and the app will suggest short and creative captions based on the image content. 4 | 5 | ## Features 6 | 7 | - **Image Upload**: Users can upload images in JPG, JPEG, or PNG formats. 8 | - **Caption Generation**: The app generates three short and creative captions for the uploaded image. 9 | - **User-Friendly Interface**: Built with Streamlit for an interactive and responsive user experience. 10 | 11 | ## Technologies Used 12 | 13 | - [Streamlit](https://streamlit.io/): A Python library to create web applications. 14 | - [Google Generative AI](https://cloud.google.com/generative-ai): Provides access to generative AI models for generating text. 15 | - [Pillow](https://pillow.readthedocs.io/en/stable/): Python Imaging Library for image processing. 16 | 17 | ## Installation 18 | 19 | To run this application locally, follow these steps: 20 | 21 | 1. **Clone the Repository**: 22 | ```bash 23 | git clone https://github.com/Rugvedrc/AI_captionGenerator.git 24 | cd AI_captionGenerator 25 | -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | import streamlit as st 2 | import google.generativeai as genai 3 | import PIL.Image 4 | import io 5 | 6 | # Function to generate captions 7 | def generate_captions(prompt): 8 | model = genai.GenerativeModel('gemini-1.5-flash-latest') 9 | response = model.generate_content([prompt,img], stream=False) 10 | 11 | # Extract only the captions (assuming they come after the introductory text) 12 | captions = response.text.split('\n', 1)[1] # Split by newline and get the captions part 13 | return captions 14 | 15 | # Streamlit GUI 16 | st.title("Creative Caption Generator") 17 | 18 | # Upload image 19 | uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"]) 20 | 21 | if uploaded_file is not None: 22 | # Display the uploaded image 23 | img = PIL.Image.open(uploaded_file) 24 | st.image(img, caption="Uploaded Image", use_column_width=True) 25 | 26 | # Input prompt for generating captions 27 | st.write("Suggest creative captions for the uploaded image:") 28 | if st.button("Generate Captions"): 29 | prompt = "Suggest 3 short and creative captions for a picture" 30 | captions = generate_captions(prompt) 31 | st.write("Generated Captions:") 32 | st.write(captions) 33 | 34 | # Directly configure API key for testing 35 | genai.configure(api_key="YOUR_API_KEY") 36 | --------------------------------------------------------------------------------