-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart_app.py
More file actions
128 lines (106 loc) · 3.8 KB
/
start_app.py
File metadata and controls
128 lines (106 loc) · 3.8 KB
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
127
128
#!/usr/bin/env python3
"""
Startup Script for Modern LinkedIn Profile Analyzer
Ensures proper environment setup and launches the application
"""
import os
import sys
import subprocess
from pathlib import Path
def check_virtual_environment():
"""Check if we're running in a virtual environment"""
return hasattr(sys, 'real_prefix') or (
hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix
)
def check_environment_file():
"""Check if .env file exists and has required keys"""
env_file = Path(".env")
if not env_file.exists():
print("❌ .env file not found!")
print("📝 Please create a .env file with your API keys:")
print()
print("OPENAI_API_KEY=your_openai_api_key_here")
print("TAVILY_API_KEY=your_tavily_api_key_here")
print()
return False
# Check for required keys
required_keys = ["OPENAI_API_KEY", "TAVILY_API_KEY"]
missing_keys = []
try:
with open(env_file, 'r') as f:
content = f.read()
for key in required_keys:
if key not in content or f"{key}=" not in content:
missing_keys.append(key)
except Exception as e:
print(f"❌ Error reading .env file: {e}")
return False
if missing_keys:
print(f"❌ Missing required API keys in .env file: {', '.join(missing_keys)}")
return False
print("✅ Environment file configured properly")
return True
def install_requirements():
"""Install requirements if needed"""
requirements_file = Path("requirements.txt")
if requirements_file.exists():
print("📦 Installing/updating dependencies...")
try:
result = subprocess.run([
sys.executable, "-m", "pip", "install", "-r", "requirements.txt"
], capture_output=True, text=True, check=True)
print("✅ Dependencies installed successfully")
except subprocess.CalledProcessError as e:
print(f"❌ Failed to install dependencies: {e}")
print(f"Error output: {e.stderr}")
return False
return True
def start_frontend():
"""Start the modern frontend"""
frontend_file = Path("frontend_modern.py")
if not frontend_file.exists():
print("❌ Frontend file 'frontend_modern.py' not found!")
return False
print("🚀 Starting Modern LinkedIn Analyzer...")
print("📱 The application will open at: http://127.0.0.1:8050")
print("🔍 Ready to analyze LinkedIn profiles!")
print()
print("💡 Press Ctrl+C to stop the application")
print("=" * 60)
try:
# Import and run the frontend
import frontend_modern
return True
except KeyboardInterrupt:
print("\n👋 Application stopped by user")
return True
except Exception as e:
print(f"❌ Failed to start frontend: {e}")
return False
def main():
"""Main startup function"""
print("🚀 Modern LinkedIn Profile Analyzer - Startup")
print("🔧 Checking environment setup...")
print()
# Check virtual environment
if check_virtual_environment():
print("✅ Running in virtual environment")
else:
print("⚠️ Not running in virtual environment")
print("💡 Consider activating your virtual environment for better isolation")
# Check environment file
if not check_environment_file():
sys.exit(1)
# Install dependencies
if not install_requirements():
print("❌ Failed to set up dependencies")
sys.exit(1)
print()
print("🎯 Environment setup complete!")
print()
# Start the application
success = start_frontend()
if not success:
sys.exit(1)
if __name__ == "__main__":
main()