-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.py
More file actions
executable file
·112 lines (97 loc) · 3.64 KB
/
start.py
File metadata and controls
executable file
·112 lines (97 loc) · 3.64 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
#!/usr/bin/env python3
"""
Startup script for Zomato Reviews Analysis System
This script provides an easy way to start the complete application.
"""
import os
import sys
import subprocess
from pathlib import Path
def check_environment():
"""Check if the environment is properly set up."""
print("Checking environment...")
# Check if .env file exists
env_file = Path(".env")
if not env_file.exists():
print("ERROR: .env file not found!")
print("Please create a .env file with your OpenAI API key:")
print("OPENAI_API_KEY=your_api_key_here")
return False
# Check if backend directory exists
backend_dir = Path("backend")
if not backend_dir.exists():
print("ERROR: Backend directory not found!")
print("Please ensure the backend/ directory exists with all required files.")
return False
# Check if frontend directory exists
frontend_dir = Path("frontend")
if not frontend_dir.exists():
print("ERROR: Frontend directory not found!")
print("Please ensure the frontend/ directory exists with all required files.")
return False
# Check if database exists
db_file = backend_dir / "zomato_reviews.sqlite"
if not db_file.exists():
print("ERROR: Database file not found!")
print("Please ensure zomato_reviews.sqlite exists in the backend/ directory.")
return False
print("Environment check passed!")
return True
def install_dependencies():
"""Install required dependencies."""
print("Installing dependencies...")
try:
subprocess.run([sys.executable, "-m", "pip", "install", "-r", "backend/requirements.txt"],
check=True, capture_output=True, text=True)
print("Dependencies installed successfully!")
return True
except subprocess.CalledProcessError as e:
print(f"Failed to install dependencies: {e}")
print(f"Error output: {e.stderr}")
return False
def start_application():
"""Start the application."""
print("Starting Zomato Reviews Analysis System...")
print("=" * 60)
print("Frontend will be available at: http://localhost:8000/")
print("API Documentation at: http://localhost:8000/api/docs")
print("Main analysis route: http://localhost:8000/api/v1/review")
print("=" * 60)
print("Press Ctrl+C to stop the server")
print()
try:
subprocess.run([sys.executable, "main.py"], check=True)
except KeyboardInterrupt:
print("\nApplication stopped by user")
except subprocess.CalledProcessError as e:
print(f"Application failed to start: {e}")
return False
return True
def main():
"""Main function."""
print("ZOMATO REVIEWS ANALYSIS SYSTEM")
print("=" * 50)
print("Complete web application with backend API and frontend interface")
print("=" * 50)
# Check environment
if not check_environment():
print("\nEnvironment check failed. Please fix the issues above.")
sys.exit(1)
# Try to start the application directly
print("\nStarting application...")
try:
start_application()
except ImportError as e:
print(f"\nMissing dependency: {e}")
print("Installing dependencies...")
if install_dependencies():
print("Dependencies installed! Starting application...")
start_application()
else:
print("Failed to install dependencies. Please check the error messages above.")
sys.exit(1)
except Exception as e:
print(f"\nApplication failed to start: {e}")
sys.exit(1)
if __name__ == "__main__":
main()