This project is a Flask-based chatbot that integrates Google Generative AI (Gemini-2.0-Flash) to provide conversational responses. It supports both text-based chat and image processing.
- Interactive chat with AI using Google GenAI API
- Session-based conversation history
- Image processing to generate AI responses based on uploaded images
- Secure API key management using environment variables
- Flask: Web framework for Python
- Google Generative AI: Gemini-2.0-Flash model
- PIL (Pillow): Image processing
- Requests: Handling HTTP requests
- dotenv: Loading environment variables
Ensure you have the following installed:
- Python 3.x
- pip (Python package manager)
-
Clone the repository:
git clone https://github.com/vikky2810/Python_ImageChat.git cd Python_ImageChat
-
Create a virtual environment (optional but recommended):
python -m venv venv source venv/bin/activate # On Windows use: venv\Scripts\activate
-
Set up environment variables:
- Create a
.env.local
file in the root directory. - Add your Google API key:
GOOGLE_API_KEY=your_api_key_here
- Create a
-
Run the application:
python app.py
-
Open your browser and go to:
http://127.0.0.1:5000/
Endpoint | Method | Description |
---|---|---|
/ |
GET | Renders the chat interface |
/get_conversation |
GET | Retrieves the conversation history |
/chat |
POST | Sends user input to AI and receives a response |
- Open the web interface.
- Enter a message in the chat box and submit.
- The AI will generate a response based on previous messages.
- Upload an image to analyze its content.
The project uses environment variables stored in a .env.local
file. The required variable is:
GOOGLE_API_KEY
- Your Google GenAI API key
- Ensure you have an active internet connection to interact with the AI model.
- API key security is crucial; do not expose it publicly.
- You can change the AI model by modifying
MODEL_ID
inapp.py
.