This project is a comprehensive Instagram automation tool that uses AI to generate unique content, stores it, and posts it to Instagram. It can be deployed as a set of Google Cloud Functions or run locally for development and testing.
- AI-Powered Content Generation: Utilizes Perplexity AI to create engaging Instagram captions, complete with relevant hashtags and image prompts.
- Dynamic Image Generation: Supports multiple image generation services, including Pollinations, Stable Horde, Hugging Face, and local Stable Diffusion, to create images based on AI-generated prompts.
- Cloud & Local Storage: Saves generated images and metadata to Google Drive and tracks posts in a Firestore database.
- Automated Posting: Posts content to Instagram based on a schedule or manual triggers.
- Flexible Scheduling: Uses Firebase Cloud Scheduler for automated content generation and posting.
- Manual Control: Provides HTTP endpoints for manual content generation and posting.
- Local Development: Includes a local runner script for easy development and testing without deployment.
/home/granth/PycharmProjects/instagram-automation/
├───.gitignore
├───firebase.json
├───instagram_session.json
├───preview_image.jpg
├───requirements.txt
├───run_local.py
└───functions/
├───config.py
├───main.py
├───services/
│ ├───image_service.py
│ ├───instagram_service.py
│ ├───perplexity_service.py
│ └───storage_service.py
└───utils/
└───database.py
- Python: Core programming language.
- Google Cloud Platform:
- Firebase Functions: For serverless automation.
- Firestore: As the database for post management.
- Google Drive: For storing generated content.
- Perplexity AI: For content and prompt generation.
- instagrapi: For Instagram API interaction.
- Pillow: For image processing.
- python-dotenv: For environment variable management.
- Python 3.11+
- A Google Cloud Platform project with Firebase enabled.
- API keys and credentials for the services you intend to use (Perplexity AI, Instagram, etc.).
-
Clone the repository:
git clone https://github.com/hey-granth/instagram-automation.git cd instagram-automation -
Create and activate a virtual environment:
python -m venv .venv source .venv/bin/activate -
Install the dependencies:
pip install -r requirements.txt
-
Set up environment variables:
- Create a
.envfile in thefunctionsdirectory. - Add the necessary environment variables to the
.envfile. Seefunctions/config.pyfor a list of required variables.
- Create a
The run_local.py script allows you to run the automation workflow locally.
-
Generate and post content:
python run_local.py --post
-
Generate content without posting:
python run_local.py --generate
-
Post pending content from the database:
python run_local.py --post-pending
-
Generate content with a specific theme:
python run_local.py --theme "your theme"
This project is designed to be deployed as Google Cloud Functions.
-
Set up the Firebase CLI:
- Follow the instructions in the Firebase documentation to install and configure the Firebase CLI.
-
Deploy the functions:
firebase deploy --only functions
Contributions are welcome! Please feel free to submit a pull request or open an issue to discuss any changes.