Spaces:
Paused
Paused
File size: 4,952 Bytes
c445bf0 |
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 |
"""
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() |