Gmail_agent / main.py
Antigravity
feat: Cloud-ready release of AI Gmail Agent with premium glassmorphism telemetry dashboard and Dockerfile
e895030
import asyncio
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import HTMLResponse
from loguru import logger
import sys
import os
if sys.platform == "win32":
try:
sys.stdout.reconfigure(encoding='utf-8')
sys.stderr.reconfigure(encoding='utf-8')
except AttributeError:
pass
from app.routes.health import router
from app.workers.email_worker import email_loop
from app.models.database import init_db
# ── Logging setup ─────────────────────────────────────────────────────────────
logger.remove()
logger.add(sys.stdout, colorize=True, format="<green>{time:HH:mm:ss}</green> | <level>{level}</level> | {message}")
logger.add("logs/agent.log", rotation="1 day", retention="7 days", level="INFO")
# ── App ───────────────────────────────────────────────────────────────────────
app = FastAPI(
title="AI Gmail Agent",
description="Automatically categorizes, filters, and replies to emails using Groq LLM",
version="2.0.0",
)
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_methods=["*"],
allow_headers=["*"],
)
app.include_router(router)
@app.on_event("startup")
async def startup_event():
init_db()
logger.info("βœ… Database initialized")
asyncio.create_task(email_loop())
@app.get("/", response_class=HTMLResponse)
async def root():
if os.path.exists("index.html"):
try:
with open("index.html", "r", encoding="utf-8") as f:
return HTMLResponse(content=f.read(), status_code=200)
except Exception as e:
logger.error(f"Error reading index.html: {e}")
return """
<html>
<head>
<title>AI Gmail Agent</title>
<style>
body { font-family: sans-serif; text-align: center; padding-top: 50px; background-color: #0f172a; color: #f8fafc; }
h1 { color: #818cf8; }
p { color: #94a3b8; }
</style>
</head>
<body>
<h1>AI Gmail Agent is Running πŸš€</h1>
<p>Ready to categorize, filter, and reply to your emails!</p>
<p>View stats at <a href="/api/stats" style="color: #38bdf8;">/api/stats</a></p>
</body>
</html>
"""