""" deploy_file_browser.py - Deploy File Browser Integration ========================================================= This script deploys the file browser integration to your existing app. Usage: python deploy_file_browser.py Features: - Creates missing directories - Backs up existing files - Deploys new file browser - Validates deployment Author: AI Lab Team Version: 1.0 """ import os import shutil from datetime import datetime from pathlib import Path def create_backup(filepath: str) -> str: """Create backup of existing file.""" if not os.path.exists(filepath): return None timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") backup_dir = "backups" os.makedirs(backup_dir, exist_ok=True) filename = os.path.basename(filepath) backup_path = os.path.join(backup_dir, f"{filename}.backup_{timestamp}") shutil.copy2(filepath, backup_path) print(f"āœ… Backed up: {filepath} -> {backup_path}") return backup_path def create_required_directories(): """Create all required directories.""" required_dirs = [ "outputs", "outputs/conversations", "outputs/user_artifacts", "outputs/feedback", "uploads", "conversations", "logs", "backups" ] print("\nšŸ“ Creating required directories...") for directory in required_dirs: try: os.makedirs(directory, exist_ok=True) print(f" āœ… {directory}/") except Exception as e: print(f" āŒ Failed: {directory}/ - {e}") print() def validate_deployment(): """Validate that deployment was successful.""" print("\nšŸ” Validating deployment...") checks = [ ("file_browser_manager.py", "File Browser Module"), ("outputs/conversations/", "Conversations Directory"), ("outputs/user_artifacts/", "User Artifacts Directory"), ] all_ok = True for path, description in checks: if os.path.exists(path): print(f" āœ… {description}") else: print(f" āŒ {description} - NOT FOUND") all_ok = False print() return all_ok def create_file_browser_module(): """Create the file_browser_manager.py module.""" # Check if already exists if os.path.exists("file_browser_manager.py"): print("āš ļø file_browser_manager.py already exists") response = input("Overwrite? (y/n): ") if response.lower() != 'y': print("Skipped file_browser_manager.py") return False create_backup("file_browser_manager.py") print("āœ… Ready to create file_browser_manager.py") print(" Please copy the File Browser Manager artifact code") return True def update_app_gradio(): """Update app_gradio.py with file browser integration.""" if not os.path.exists("app_gradio.py"): print("āŒ app_gradio.py not found!") return False # Backup existing create_backup("app_gradio.py") print("āœ… Backed up app_gradio.py") print(" Please replace with updated version from artifacts") return True def show_post_deployment_instructions(): """Show instructions after deployment.""" print("\n" + "=" * 60) print("POST-DEPLOYMENT INSTRUCTIONS") print("=" * 60) print() print("1. Copy file_browser_manager.py from the artifact") print(" Save as: file_browser_manager.py") print() print("2. Copy updated app_gradio.py from the artifact") print(" Save as: app_gradio.py (will replace existing)") print() print("3. Restart your application:") print(" python app_gradio.py") print() print("4. Test the file browser:") print(" - Generate some files") print(" - Click the 'File Browser' tab") print(" - Try downloading files") print() print("5. If issues occur, restore from backups/ directory") print() print("=" * 60) def main(): """Main deployment process.""" print("=" * 60) print("FILE BROWSER INTEGRATION DEPLOYMENT") print("=" * 60) print() print("This will:") print(" 1. Create required directories") print(" 2. Backup existing files") print(" 3. Guide you through integration") print() response = input("Continue? (y/n): ") if response.lower() != 'y': print("Deployment cancelled.") return # Step 1: Create directories create_required_directories() # Step 2: Prepare file browser module create_file_browser_module() # Step 3: Update app_gradio update_app_gradio() # Step 4: Validate validate_deployment() # Step 5: Show instructions show_post_deployment_instructions() print("āœ… Deployment preparation complete!") print() if __name__ == "__main__": main()