-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
91 lines (75 loc) · 2.69 KB
/
run.py
File metadata and controls
91 lines (75 loc) · 2.69 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
#!/usr/bin/env python3
"""
TRANSLai - Run Script
Correct version for handling reload mode in uvicorn
"""
import os
import sys
import platform
from pathlib import Path
import time
def setup_environment():
"""Setup environment and correct paths"""
project_root = Path(__file__).parent.resolve()
os.chdir(project_root)
print(f"✅ Project directory: {project_root}")
print(f"💻 System: {platform.system()} {platform.release()}")
print(f"🐍 Python: {sys.version.split()[0]}")
# Add project directory to Python path
if str(project_root) not in sys.path:
sys.path.insert(0, str(project_root))
return project_root
def main():
"""Main function"""
print("=" * 60)
print("🚀 TRANSLai - Multilingual Prompt Translation & Enhancement")
print("=" * 60)
start_time = time.time()
# Setup environment
project_root = setup_environment()
# Check for .env file
env_file = project_root / ".env"
if not env_file.exists():
print("⚠️ Warning: .env file not found")
print(" Creating .env file from .env.example")
import shutil
shutil.copy2(project_root / ".env.example", env_file)
print(" ✅ .env file created")
try:
# Run uvicorn with import string (correct solution for reload)
import uvicorn
print("\n🚀 Starting TRANSLai server...")
print("🌐 Address: http://0.0.0.0:8000")
print("📚 API Docs: http://localhost:8000/api/docs")
print("🔧 Development mode: Auto-reload enabled")
# Use import string instead of importing app object directly
uvicorn.run(
"translai.app.main:app", # ← This is the correct solution
host="0.0.0.0",
port=8000,
reload=True,
reload_dirs=["translai"],
log_level="info",
access_log=False
)
except ImportError as e:
print(f"\n❌ Import error: {e}")
print("\n💡 Suggested solutions:")
print(" 1. Check project structure")
print(" 2. Ensure virtual environment is activated")
print(" 3. Try: pip install -r requirements.txt")
except Exception as e:
print(f"\n❌ Unexpected error: {e}")
import traceback
traceback.print_exc()
# Performance info
elapsed_time = time.time() - start_time
print(f"\n⏱️ Initialization time: {elapsed_time:.2f} seconds")
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
print("\n\n🛑 Server stopped manually")
except Exception as e:
print(f"\n❌ Fatal error: {e}")
sys.exit(1)