-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
80 lines (65 loc) · 2.44 KB
/
run.py
File metadata and controls
80 lines (65 loc) · 2.44 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
#!/usr/bin/env python3
"""
Plant Recognizer - Automatic Setup and Server Launcher
This script installs requirements and starts the FastAPI Backend.
"""
import subprocess
import sys
import os
import time
def install_requirements():
"""Install all required packages from requirements.txt"""
print("\n" + "="*60)
print("🌿 Plant Recognizer - Dependency Installation")
print("="*60 + "\n")
requirements_path = os.path.join(os.path.dirname(__file__), 'requirements.txt')
if not os.path.exists(requirements_path):
print("❌ Error: requirements.txt not found!")
sys.exit(1)
print("📦 Installing/Verifying required packages...")
print("-" * 60)
try:
subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-r', requirements_path])
print("\n✅ Dependencies ready!\n")
return True
except subprocess.CalledProcessError as e:
print(f"\n❌ Error installing packages: {e}")
sys.exit(1)
def run_server():
"""Run the FastAPI Server"""
server_path = os.path.join(os.path.dirname(__file__), 'server.py')
if not os.path.exists(server_path):
print(f"❌ Error: server.py not found at {server_path}")
sys.exit(1)
print("🚀 Starting Backend Server...")
print(f"📡 API will be available at: http://localhost:8000")
print("="*60 + "\n")
try:
# Run server.py using the current python executable
subprocess.run([sys.executable, server_path], check=True)
except subprocess.CalledProcessError as e:
print("\n" + "!" * 60)
print("❌ Server failed to start!")
print("!" * 60)
print("\nPossible Causes:")
print("1. Port 8000 is already in use.")
print(" -> Check if another terminal is running 'python server.py' or 'run.py'")
print(" -> Stop the other process and try again.")
print("-" * 60)
print(f"Details: {e}")
sys.exit(1)
except KeyboardInterrupt:
print("\n\n⚠️ Server stopped by user")
sys.exit(0)
def main():
try:
install_requirements()
print("ℹ️ Note: Please ensure the React Client is running in a separate terminal:")
print(" cd Client && npm run dev\n")
time.sleep(2)
run_server()
except Exception as e:
print(f"\n❌ Unexpected error: {e}")
sys.exit(1)
if __name__ == '__main__':
main()