-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathstart_backend.py
More file actions
97 lines (79 loc) · 2.68 KB
/
start_backend.py
File metadata and controls
97 lines (79 loc) · 2.68 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
#!/usr/bin/env python3
"""
EmoLearn Backend Server Startup Script
This script helps you start the backend server for the EmoLearn project.
"""
import os
import sys
import subprocess
import time
def check_python_version():
"""Check if Python version is compatible"""
if sys.version_info < (3, 8):
print("❌ Error: Python 3.8 or higher is required")
print(f"Current version: {sys.version}")
return False
print(f"✅ Python version: {sys.version.split()[0]}")
return True
def check_requirements():
"""Check if required packages are installed"""
required_packages = [
'fastapi', 'uvicorn', 'flask', 'opencv-python',
'mediapipe', 'deepface', 'numpy', 'pandas'
]
missing_packages = []
for package in required_packages:
try:
__import__(package.replace('-', '_'))
except ImportError:
missing_packages.append(package)
if missing_packages:
print(f"❌ Missing packages: {', '.join(missing_packages)}")
print("Please install them using: pip install -r backend/requirements.txt")
return False
print("✅ All required packages are installed")
return True
def start_server():
"""Start the FastAPI server"""
print("\n🚀 Starting EmoLearn Backend Server...")
print("=" * 50)
# Change to backend directory
backend_dir = os.path.join(os.path.dirname(__file__), 'backend')
if not os.path.exists(backend_dir):
print(f"❌ Backend directory not found: {backend_dir}")
return False
os.chdir(backend_dir)
try:
# Start the server
print("📍 Server will be available at: http://localhost:8000")
print("📍 Games will be available at: http://localhost:8000/games/{emotion}/{game_name}")
print("📍 API documentation at: http://localhost:8000/docs")
print("\n⏳ Starting server... (Press Ctrl+C to stop)")
print("-" * 50)
# Run the server
subprocess.run([
sys.executable, "-m", "uvicorn",
"main:app",
"--host", "127.0.0.1",
"--port", "8000",
"--reload"
])
except KeyboardInterrupt:
print("\n\n🛑 Server stopped by user")
except Exception as e:
print(f"\n❌ Error starting server: {e}")
return False
return True
def main():
"""Main function"""
print("🎮 EmoLearn Backend Server Startup")
print("=" * 40)
# Check prerequisites
if not check_python_version():
return
if not check_requirements():
return
# Start server
start_server()
if __name__ == "__main__":
main()