Piyush-linux/Gmail-AI-Agent

โ˜… 0Forks 0PythonGitHub โ†—Compare

README

๐Ÿ“ง Gmail Agent Summarizer

This Python application uses the Gmail API and OpenAI API to summarize the last 10 emails in your Gmail account.

โœจ Features

  • ๐Ÿš€ Fetches the most recent 10 emails from your Gmail account.
  • ๐Ÿ“ฉ Retrieves and cleans the email content (text and HTML).
  • ๐Ÿค– Summarizes the email content using OpenAI's GPT-based API.

๐Ÿ Python Setup

mkdir gmail-ai-agent
cd gmail-ai-agent
python -m venv ./venv
source ./venv/bin/activate
pip install google-auth-oauthlib google-auth-httplib2 google-api-python-client beautifulsoup4 openai

โ˜๏ธ Google Cloud Setup

  1. ๐ŸŒ Go to Google Cloud Console and create a new project.
  2. โœ… Enable the Gmail API for your project.
  3. ๐Ÿ›  Configure the OAuth Consent Screen:
    • Fill in the required details.
    • Add the scope https://www.googleapis.com/auth/gmail.readonly.
  4. ๐Ÿ—‚ Create credentials for the OAuth client:
    • Choose Desktop App as the application type.
    • Download the credentials file and rename it to credentials.json.

๐Ÿ”‘ OpenAI API Setup

  1. โœ๏ธ Create an account on OpenAI.
  2. ๐Ÿ” Generate an API key from the OpenAI API Portal.

๐Ÿƒโ€โ™‚๏ธ Run the Code

  1. ๐Ÿ”ง Export your OpenAI API key as an environment variable:
export OPENAI_API_KEY='your-openai-api-key'
  1. โ–ถ๏ธ Run the application:
python app.py

๐Ÿ›  How It Works

  1. Authenticate with Gmail API:
    • Handles OAuth2 authentication.
    • Stores and refreshes credentials using token.pickle.
  2. Fetch Recent Emails:
    • Retrieves up to 10 recent emails from your Gmail inbox.
    • Extracts subject, sender, date, and content.
  3. Clean and Summarize Content:
    • Parses and cleans email content using BeautifulSoup.
    • Summarizes email content using OpenAI's GPT model.
  4. Output Summaries:
    • Displays a concise summary of each email.

๐Ÿ“‹ Notes

  • ๐Ÿ—ƒ Ensure that credentials.json is in the same directory as the Python script.
  • ๐Ÿ”„ The token.pickle file will be created during the first run to store authentication tokens.
  • ๐Ÿ“œ Ensure your OpenAI API key is kept secure and not hardcoded in the script.

๐Ÿ“œ License

This project is licensed under the MIT License. Feel free to modify and distribute it as needed.

Contributors

Piyush-linux

Issues