HarshitX commited on
Commit
cc77c9f
·
verified ·
1 Parent(s): 4569cf3

Upload 4 files

Browse files

# Image Insights Generator

This project is a Streamlit application that allows users to upload an image and ask questions about it. The application utilizes the Gemini Pro Vision AI to analyze the image and provide insights based on the user's input.

## Features

- **Image Upload**: Users can upload images in JPG, JPEG, or PNG formats.
- **Prompt Input**: Users can ask questions about the uploaded image.
- **AI Insights**: The app uses Gemini Pro Vision to analyze the image and generate insights based on the prompt.
- **Interactive UI**: Features a sidebar with instructions, a progress bar for image analysis, and a celebratory balloon effect when analysis is complete.

## Installation

To run this application locally, follow these steps:

1. **Clone the repository:**

```bash
git clone https://github.com/your-username/image-insights-generator.git
cd image-insights-generator
```

2. **Create a virtual environment and activate it:**

```bash
python -m venv venv
source venv/bin/activate # On Windows, use `venv\Scripts\activate`
```

3. **Install the required packages:**

```bash
pip install -r requirements.txt
```

4. **Set up the Gemini Pro Vision API key:**

Replace the placeholder API key in the code with your actual API key:
```python
genai.configure(api_key="YOUR_API_KEY")
```

5. **Run the Streamlit app:**

```bash
streamlit run app.py
```

## Usage

1. **Upload an Image**: Click on the file uploader and select an image file (JPG, JPEG, or PNG).
2. **Enter a Question**: Type your question about the image in the provided text input box.
3. **Generate Insights**: Click the "Generate Insights" button to get AI insights about the image.

## Example

1. **Upload an Image:**
![Upload Image](https://via.placeholder.com/400x200?text=Upload+an+Image)

2. **Enter a Question:**
![Enter a Question](https://via.placeholder.com/400x200?text=Enter+a+Question)

3. **Generate Insights:**
![Generate Insights](https://via.placeholder.com/400x200?text=Generate+Insights)

## Contributing

Contributions are welcome! Please fork this repository and submit a pull request with your changes.

## License

This project is licensed under the MIT License. See the file for details.

## Acknowledgements

- [Streamlit](https://streamlit.io/) - The framework used to build the application.
- [Gemini Pro Vision]([https://www.example.com](https://console.cloud.google.com/vertex-ai/generative/multimodal/create/)) - The AI service used for image analysis.

## Contact

For any questions or feedback, please reach out to communication.harshit10@gmail.com.

Files changed (4) hide show
  1. .env +1 -0
  2. .gitignore +1 -0
  3. app.py +85 -0
  4. requirements.txt +4 -0
.env ADDED
@@ -0,0 +1 @@
 
 
1
+ GOGGLE_API_KEY = "AIzaSyBaxMCjBV5fBlsKUmFb-8SGgkiirv1ZKck"
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ .env
app.py ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import google.generativeai as genai
3
+
4
+ import io
5
+ import os
6
+
7
+ from dotenv import load_dotenv
8
+ from PIL import Image
9
+
10
+ load_dotenv()
11
+
12
+ # Configure the API key
13
+ genai.configure(api_key= "AIzaSyBaxMCjBV5fBlsKUmFb-8SGgkiirv1ZKck")
14
+
15
+ # Set up the model
16
+ model = genai.GenerativeModel('gemini-1.5-flash-latest')
17
+
18
+ def get_gemini_response(image_blob, prompt):
19
+ response = model.generate_content([prompt, image_blob])
20
+ return response.text
21
+
22
+ # Streamlit app
23
+ st.set_page_config(page_title="Image Insights Generator", page_icon="📷", layout="wide")
24
+
25
+ # Sidebar with instructions and additional information
26
+ st.sidebar.title("Instructions")
27
+ st.sidebar.write("""
28
+ 1. Upload an image using the file uploader.
29
+ 2. Enter a question about the image in the text input box.
30
+ 3. Click the "Generate Insights" button to get AI insights about the image.
31
+ """)
32
+ st.sidebar.markdown("---")
33
+ st.sidebar.caption("Created with Streamlit and Gemini Pro Vision")
34
+
35
+ # Main content
36
+ st.title("📷 Image Insights Generator")
37
+ st.write("Upload an image and ask a question about it. Our AI will analyze the image and provide insights!")
38
+
39
+ # File uploader for image
40
+ uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
41
+
42
+ if uploaded_file is not None:
43
+ # Display the uploaded image
44
+ image = Image.open(uploaded_file)
45
+ st.image(image, caption="Uploaded Image", use_column_width=True)
46
+
47
+ # Text input for the prompt
48
+ prompt = st.text_input("What would you like to know about this image?", placeholder="Enter your question here...")
49
+
50
+ if st.button("Generate Insights"):
51
+ with st.spinner("Analyzing the image..."):
52
+ # Prepare the image for the Gemini API
53
+ img_byte_arr = io.BytesIO()
54
+ image.save(img_byte_arr, format='PNG')
55
+ img_byte_arr = img_byte_arr.getvalue()
56
+
57
+ # Create a Blob from the image data
58
+ image_blob = {
59
+ "mime_type": "image/png",
60
+ "data": img_byte_arr
61
+ }
62
+
63
+ # Progress bar
64
+ progress_bar = st.progress(0)
65
+
66
+ for i in range(1, 101):
67
+ progress_bar.progress(i)
68
+ if i == 100:
69
+ # Get the response from Gemini Pro Vision
70
+ response = get_gemini_response(image_blob, prompt)
71
+
72
+ # Display the response
73
+ st.subheader("🔍 AI Insights:")
74
+ st.write(response)
75
+ st.balloons() # Add some celebration!
76
+
77
+ # Custom CSS for styling
78
+ st.markdown("""
79
+ <style>
80
+ body {
81
+ font-family: 'Arial', sans-serif;
82
+ }
83
+ </style>
84
+ """, unsafe_allow_html=True)
85
+
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ streamlit
2
+ google-generativeai
3
+ python-dotenv
4
+ Pillow