-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
143 lines (117 loc) · 4.05 KB
/
run.py
File metadata and controls
143 lines (117 loc) · 4.05 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/env python3
"""
Startup script for Sign Language Learning App
"""
import os
import sys
import subprocess
from pathlib import Path
def check_dependencies():
"""Check if required dependencies are installed"""
print("🔍 Checking dependencies...")
try:
import flask
import cv2
import cvzone
import mediapipe
print("✅ All core dependencies found")
return True
except ImportError as e:
print(f"❌ Missing dependency: {e}")
print("Please install dependencies: pip install -r requirements.txt")
return False
def check_environment():
"""Check environment configuration"""
print("🔍 Checking environment...")
# Check if .env file exists
if not os.path.exists('.env'):
print("⚠️ .env file not found")
print(" Creating .env from template...")
if os.path.exists('env_example.txt'):
with open('env_example.txt', 'r') as f:
content = f.read()
with open('.env', 'w') as f:
f.write(content)
print("✅ .env file created from template")
print(" Please edit .env file with your API keys")
return False
else:
print("❌ env_example.txt not found")
return False
# Check Firebase credentials
if not os.path.exists('firebase-credentials.json'):
print("ℹ️ firebase-credentials.json not found")
print(" ✅ Switching to OFFLINE MODE (using SQLite local database)")
print(" Use this mode if you don't have Firebase set up.")
return True
def run_app():
"""Run the Flask application"""
print("🚀 Starting Sign Language Learning App...")
# Set default port
port = os.getenv('PORT', 5000)
try:
# Import and run the app
from app import app
print(f"✅ App loaded successfully")
print(f"🌐 Server starting on http://localhost:{port}")
print("📱 Open your browser and navigate to the URL above")
print("🔄 Press Ctrl+C to stop the server")
print("-" * 50)
app.run(
host='0.0.0.0',
port=port,
debug=os.getenv('DEBUG', 'True').lower() == 'true'
)
except ImportError as e:
print(f"❌ Error importing app: {e}")
print("Please check your installation and dependencies")
return False
except Exception as e:
print(f"❌ Error starting app: {e}")
return False
def run_demo():
"""Run the demo version"""
print("🎮 Running in demo mode...")
print("This mode simulates the app without external dependencies")
try:
from demo import main
main()
except ImportError:
print("❌ Demo module not found")
return False
except Exception as e:
print(f"❌ Error running demo: {e}")
return False
def main():
"""Main function"""
print("🤟 Sign Language Learning App")
print("=" * 40)
# Check if running in demo mode
if len(sys.argv) > 1 and sys.argv[1] == 'demo':
run_demo()
return
# Check dependencies
if not check_dependencies():
print("\n💡 Try running in demo mode:")
print(" python run.py demo")
return
# Check environment
env_ok = check_environment()
if not env_ok:
print("\n⚠️ Environment not fully configured")
print("The app may not work properly without API keys")
print("You can still try running it, or use demo mode:")
print(" python run.py demo")
response = input("\nContinue anyway? (y/n): ").lower()
if response != 'y':
return
# Run the app
run_app()
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
print("\n👋 App stopped by user")
except Exception as e:
print(f"\n❌ Unexpected error: {e}")
print("Please check the error message above")