File size: 3,108 Bytes
368277b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
"""
Main entry point for the Digital Assistant application.
A comprehensive assistant for bookmarks, email management, and web search.
Built with Smolagents and Gradio.
"""

import os
import sys
from dotenv import load_dotenv


def check_environment():
    """Check if all required environment variables are present"""
    load_dotenv()

    # Check for HF_TOKEN
    if not os.getenv("HF_TOKEN"):
        print("❌ Error: HF_TOKEN not found in environment variables.")
        print("Please set your Hugging Face token in a .env file or as an environment variable.")
        print("You can get your token from: https://huggingface.co/settings/tokens")
        return False

    # Check for Gmail OAuth credentials (environment variables)
    google_client_id = os.getenv("GOOGLE_CLIENT_ID")
    google_client_secret = os.getenv("GOOGLE_CLIENT_SECRET")
    google_refresh_token = os.getenv("GOOGLE_REFRESH_TOKEN")

    if not google_client_id or not google_client_secret:
        print("⚠️  Warning: Gmail OAuth credentials not found in environment variables.")
        print("Please set GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET for Gmail integration.")
        print("Run 'python scripts/setup_gmail_credentials.py' to set up Gmail credentials.")

    elif not google_refresh_token:
        print("⚠️  Warning: GOOGLE_REFRESH_TOKEN not found.")
        print("Gmail integration may require re-authentication.")
        print("Run 'python scripts/setup_gmail_credentials.py' to obtain the refresh token.")
    else:
        print("✅ Gmail OAuth credentials found in environment variables.")

    return True


def main():
    """Main application entry point"""
    print("🚀 Starting Digital Assistant...")

    # Check environment
    if not check_environment():
        sys.exit(1)

    try:
        # Import here to avoid import errors before environment check
        from src.interfaces.gradio_interface import demo

        print("✅ Environment check passed")
        print("🔖 Digital Assistant ready!")
        print("🤔 Now with real-time thinking display!")
        print("📧 Email • 🌐 Web Search • 🔖 Bookmarks")
        print("🌐 Launching web interface...")

        # Launch the interface
        print("🌐 Access your assistant at: http://localhost:7860")
        print("📱 A public URL will also be generated for external access")
        print("🔧 The browser should open automatically")

        demo.launch(
            # share=True,  # Set to True if you want a public URL
            server_name="127.0.0.1",  # Use localhost for better compatibility
            server_port=7860,
            show_error=True,
            quiet=False,
            inbrowser=True,  # Automatically open browser
            show_api=False,
        )

    except ImportError as e:
        print(f"❌ Import error: {e}")
        print("Please ensure all dependencies are installed: pip install -e .")
        sys.exit(1)

    except Exception as e:
        print(f"❌ Error starting Digital Assistant: {e}")
        sys.exit(1)


if __name__ == "__main__":
    main()