File size: 4,036 Bytes
80a1334
 
aae35f1
80a1334
 
 
 
 
 
 
 
 
aae35f1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80a1334
 
aae35f1
 
80a1334
 
 
 
 
 
 
 
aae35f1
80a1334
 
aae35f1
80a1334
 
aae35f1
80a1334
 
 
aae35f1
 
80a1334
 
 
 
aae35f1
 
80a1334
 
aae35f1
80a1334
 
 
 
aae35f1
 
80a1334
 
 
aae35f1
 
 
 
 
 
 
 
80a1334
 
 
aae35f1
80a1334
 
 
aae35f1
80a1334
 
 
aae35f1
80a1334
 
aae35f1
80a1334
 
 
 
aae35f1
 
 
80a1334
 
 
 
 
 
 
 
 
aae35f1
80a1334
 
 
aae35f1
80a1334
aae35f1
 
 
 
 
80a1334
 
 
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env python3
"""
Simple launcher script for the Gradio app with better error handling and debug logging.
"""

import os
import sys
from dotenv import load_dotenv

# Load environment variables
load_dotenv()

# Import and setup debug configuration
try:
    from debug_config import setup_debug_logging, log_system_info, log_session_end
    import logging
    
    # Setup debug logging (can be controlled via environment variable)
    debug_level = os.getenv('DEBUG_LEVEL', 'INFO')
    log_to_file = os.getenv('LOG_TO_FILE', 'true').lower() == 'true'
    log_to_console = os.getenv('LOG_TO_CONSOLE', 'true').lower() == 'true'
    
    setup_debug_logging(log_level=debug_level, log_to_file=log_to_file, log_to_console=log_to_console)
    logger = logging.getLogger(__name__)
    
except ImportError:
    # Fallback if debug_config is not available
    import logging
    logging.basicConfig(level=logging.INFO)
    logger = logging.getLogger(__name__)

def check_requirements():
    """Check if all required packages are installed."""
    logger.info("Checking package requirements...")
    
    required_packages = [
        'gradio', 'google.generativeai', 'torch', 'psutil'
    ]
    
    missing = []
    for package in required_packages:
        try:
            __import__(package.replace('-', '_'))
            logger.debug(f"βœ“ Package {package} found")
        except ImportError:
            missing.append(package)
            logger.warning(f"βœ— Package {package} missing")
    
    if missing:
        logger.error(f"Missing packages: {', '.join(missing)}")
        print(f"Missing packages: {', '.join(missing)}")
        print("Please run: pip install -r requirements.txt")
        return False
    
    logger.info("All required packages are available")
    return True

def check_api_key():
    """Check if API key is configured."""
    logger.info("Checking API key configuration...")
    
    api_key = os.getenv('GOOGLE_API_KEY')
    if not api_key:
        logger.error("GOOGLE_API_KEY not found in environment variables")
        print("ERROR: GOOGLE_API_KEY not found in .env file")
        print("Please add your Gemini API key to the .env file:")
        print("GOOGLE_API_KEY=your_api_key_here")
        return False
    
    logger.info(f"API key found (length: {len(api_key)})")
    return True

def main():
    logger.info("Starting Auto Diffusers Config application")
    print("πŸš€ Starting Auto Diffusers Config Gradio App...")
    
    # Log system information
    try:
        log_system_info()
    except:
        logger.warning("Could not log system info")
    
    # Check requirements
    if not check_requirements():
        logger.error("Requirements check failed, exiting")
        sys.exit(1)
    
    if not check_api_key():
        logger.error("API key check failed, exiting")
        sys.exit(1)
    
    try:
        logger.info("Importing Gradio interface module")
        from gradio_app import create_gradio_interface
        
        logger.info("All requirements satisfied, launching interface")
        print("βœ… All requirements satisfied")
        print("🌐 Launching Gradio interface...")
        
        interface = create_gradio_interface()
        logger.info("Gradio interface created successfully")
        
        logger.info("Starting Gradio server on 0.0.0.0:7860")
        interface.launch(
            server_name="0.0.0.0",
            server_port=7860,
            share=True,
            show_error=True,
            inbrowser=True
        )
        
    except ImportError as e:
        logger.error(f"Import error: {e}")
        print(f"Import error: {e}")
        print("Make sure all dependencies are installed: pip install -r requirements.txt")
    except Exception as e:
        logger.error(f"Error launching app: {e}", exc_info=True)
        print(f"Error launching app: {e}")
    finally:
        try:
            log_session_end()
        except:
            logger.warning("Could not log session end")

if __name__ == "__main__":
    main()