Spaces:
Sleeping
Sleeping
| # 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() | |