Spaces:
Sleeping
Sleeping
File size: 7,465 Bytes
f93a960 | 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 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | # SyncMaster Enhanced Setup Script
# تشغيل SyncMaster المحسن مع دعم الترجمة
import subprocess
import sys
import os
import time
from pathlib import Path
def print_header():
print("=" * 60)
print("🎵 SyncMaster Enhanced - AI-Powered Translation Setup")
print("منصة المزامنة الذكية مع دعم الترجمة بالذكاء الاصطناعي")
print("=" * 60)
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("خطأ: يتطلب Python 3.8 أو أحدث")
return False
print(f"✅ Python version: {sys.version}")
return True
def install_requirements():
"""Install required packages"""
print("\n📦 Installing required packages...")
print("تثبيت الحزم المطلوبة...")
try:
subprocess.check_call([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"])
print("✅ All packages installed successfully!")
print("تم تثبيت جميع الحزم بنجاح!")
return True
except subprocess.CalledProcessError as e:
print(f"❌ Error installing packages: {e}")
print(f"خطأ في تثبيت الحزم: {e}")
return False
def check_env_file():
"""Check if .env file exists and has required keys"""
env_path = Path(".env")
if not env_path.exists():
print("❌ .env file not found!")
print("ملف .env غير موجود!")
create_env_file()
return False
with open(env_path, 'r') as f:
content = f.read()
if "GEMINI_API_KEY" not in content:
print("❌ GEMINI_API_KEY not found in .env file!")
print("مفتاح GEMINI_API_KEY غير موجود في ملف .env!")
return False
print("✅ Environment file configured correctly!")
print("ملف البيئة مُعدّ بشكل صحيح!")
return True
def create_env_file():
"""Create a template .env file"""
print("\n📝 Creating .env template file...")
print("إنشاء ملف قالب .env...")
env_content = """# SyncMaster Configuration
# إعدادات SyncMaster
# Gemini AI API Key (Required for transcription and translation)
# مفتاح Gemini AI (مطلوب للنسخ والترجمة)
GEMINI_API_KEY=your_gemini_api_key_here
# Optional: Set default language (en/ar)
# اختياري: تعيين اللغة الافتراضية
DEFAULT_LANGUAGE=en
# Optional: Enable translation by default
# اختياري: تفعيل الترجمة افتراضياً
ENABLE_TRANSLATION=true
# Optional: Default target language for translation
# اختياري: اللغة المستهدفة للترجمة افتراضياً
DEFAULT_TARGET_LANGUAGE=ar
"""
with open(".env", "w", encoding="utf-8") as f:
f.write(env_content)
print("✅ .env template created!")
print("تم إنشاء قالب .env!")
print("\n🔑 Please edit .env file and add your Gemini API key:")
print("يرجى تحرير ملف .env وإضافة مفتاح Gemini API الخاص بك:")
print("GEMINI_API_KEY=your_actual_api_key")
def start_recorder_server():
"""Start the Flask recorder server"""
print("\n🚀 Starting recorder server...")
print("بدء تشغيل خادم التسجيل...")
try:
# Start recorder server in background
process = subprocess.Popen([
sys.executable, "recorder_server.py"
], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
print("✅ Recorder server started on http://localhost:5001")
print("تم بدء تشغيل خادم التسجيل على http://localhost:5001")
return process
except Exception as e:
print(f"❌ Error starting recorder server: {e}")
print(f"خطأ في بدء تشغيل خادم التسجيل: {e}")
return None
def start_streamlit_app():
"""Start the main Streamlit application"""
print("\n🌟 Starting SyncMaster main application...")
print("بدء تشغيل تطبيق SyncMaster الرئيسي...")
try:
subprocess.run([
sys.executable, "-m", "streamlit", "run", "app.py",
"--server.port", "8501",
"--server.address", "localhost"
])
except KeyboardInterrupt:
print("\n👋 Application stopped by user.")
print("تم إيقاف التطبيق بواسطة المستخدم.")
except Exception as e:
print(f"❌ Error starting Streamlit app: {e}")
print(f"خطأ في بدء تشغيل تطبيق Streamlit: {e}")
def print_usage_instructions():
"""Print usage instructions"""
print("\n📖 Usage Instructions / تعليمات الاستخدام:")
print("-" * 40)
print("1. Open your browser and go to: http://localhost:8501")
print(" افتح متصفحك واذهب إلى: http://localhost:8501")
print("\n2. For recording, the recorder interface is at: http://localhost:5001")
print(" للتسجيل، واجهة التسجيل متاحة على: http://localhost:5001")
print("\n3. Choose your language (English/العربية) from the sidebar")
print(" اختر لغتك (English/العربية) من الشريط الجانبي")
print("\n4. Enable translation and select target language")
print(" فعّل الترجمة واختر اللغة المستهدفة")
print("\n5. Upload audio or record directly from microphone")
print(" ارفع ملف صوتي أو سجل مباشرة من الميكروفون")
print("\n📚 For detailed instructions, see README_AR.md")
print("للتعليمات المفصلة، راجع ملف README_AR.md")
def main():
"""Main setup function"""
print_header()
# Check Python version
if not check_python_version():
return
# Install requirements
if not install_requirements():
return
# Check environment configuration
if not check_env_file():
print("\n⚠️ Please configure your .env file before running the application.")
print("يرجى إعداد ملف .env قبل تشغيل التطبيق.")
return
print("\n🎉 Setup completed successfully!")
print("تم الإعداد بنجاح!")
print_usage_instructions()
# Ask user if they want to start the application
print("\n" + "=" * 60)
start_now = input("Start SyncMaster now? (y/n) / تشغيل SyncMaster الآن؟ (y/n): ").lower().strip()
if start_now in ['y', 'yes', 'نعم']:
# Start recorder server
recorder_process = start_recorder_server()
# Wait a moment for server to start
time.sleep(2)
# Start main application
try:
start_streamlit_app()
finally:
# Clean up recorder server
if recorder_process:
recorder_process.terminate()
print("\n🧹 Cleaning up processes...")
print("تنظيف العمليات...")
else:
print("\n👋 Setup complete. Run 'python setup_enhanced.py' when ready.")
print("الإعداد مكتمل. شغّل 'python setup_enhanced.py' عندما تكون جاهزاً.")
if __name__ == "__main__":
main()
|