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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
deploy_file_browser.py - Deploy File Browser Integration
|
| 3 |
+
=========================================================
|
| 4 |
+
|
| 5 |
+
This script deploys the file browser integration to your existing app.
|
| 6 |
+
|
| 7 |
+
Usage:
|
| 8 |
+
python deploy_file_browser.py
|
| 9 |
+
|
| 10 |
+
Features:
|
| 11 |
+
- Creates missing directories
|
| 12 |
+
- Backs up existing files
|
| 13 |
+
- Deploys new file browser
|
| 14 |
+
- Validates deployment
|
| 15 |
+
|
| 16 |
+
Author: AI Lab Team
|
| 17 |
+
Version: 1.0
|
| 18 |
+
"""
|
| 19 |
+
|
| 20 |
+
import os
|
| 21 |
+
import shutil
|
| 22 |
+
from datetime import datetime
|
| 23 |
+
from pathlib import Path
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def create_backup(filepath: str) -> str:
|
| 27 |
+
"""Create backup of existing file."""
|
| 28 |
+
if not os.path.exists(filepath):
|
| 29 |
+
return None
|
| 30 |
+
|
| 31 |
+
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 32 |
+
backup_dir = "backups"
|
| 33 |
+
os.makedirs(backup_dir, exist_ok=True)
|
| 34 |
+
|
| 35 |
+
filename = os.path.basename(filepath)
|
| 36 |
+
backup_path = os.path.join(backup_dir, f"{filename}.backup_{timestamp}")
|
| 37 |
+
|
| 38 |
+
shutil.copy2(filepath, backup_path)
|
| 39 |
+
print(f"β
Backed up: {filepath} -> {backup_path}")
|
| 40 |
+
|
| 41 |
+
return backup_path
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def create_required_directories():
|
| 45 |
+
"""Create all required directories."""
|
| 46 |
+
required_dirs = [
|
| 47 |
+
"outputs",
|
| 48 |
+
"outputs/conversations",
|
| 49 |
+
"outputs/user_artifacts",
|
| 50 |
+
"outputs/feedback",
|
| 51 |
+
"uploads",
|
| 52 |
+
"conversations",
|
| 53 |
+
"logs",
|
| 54 |
+
"backups"
|
| 55 |
+
]
|
| 56 |
+
|
| 57 |
+
print("\nπ Creating required directories...")
|
| 58 |
+
|
| 59 |
+
for directory in required_dirs:
|
| 60 |
+
try:
|
| 61 |
+
os.makedirs(directory, exist_ok=True)
|
| 62 |
+
print(f" β
{directory}/")
|
| 63 |
+
except Exception as e:
|
| 64 |
+
print(f" β Failed: {directory}/ - {e}")
|
| 65 |
+
|
| 66 |
+
print()
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
def validate_deployment():
|
| 70 |
+
"""Validate that deployment was successful."""
|
| 71 |
+
print("\nπ Validating deployment...")
|
| 72 |
+
|
| 73 |
+
checks = [
|
| 74 |
+
("file_browser_manager.py", "File Browser Module"),
|
| 75 |
+
("outputs/conversations/", "Conversations Directory"),
|
| 76 |
+
("outputs/user_artifacts/", "User Artifacts Directory"),
|
| 77 |
+
]
|
| 78 |
+
|
| 79 |
+
all_ok = True
|
| 80 |
+
|
| 81 |
+
for path, description in checks:
|
| 82 |
+
if os.path.exists(path):
|
| 83 |
+
print(f" β
{description}")
|
| 84 |
+
else:
|
| 85 |
+
print(f" β {description} - NOT FOUND")
|
| 86 |
+
all_ok = False
|
| 87 |
+
|
| 88 |
+
print()
|
| 89 |
+
|
| 90 |
+
return all_ok
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
def create_file_browser_module():
|
| 94 |
+
"""Create the file_browser_manager.py module."""
|
| 95 |
+
|
| 96 |
+
# Check if already exists
|
| 97 |
+
if os.path.exists("file_browser_manager.py"):
|
| 98 |
+
print("β οΈ file_browser_manager.py already exists")
|
| 99 |
+
response = input("Overwrite? (y/n): ")
|
| 100 |
+
if response.lower() != 'y':
|
| 101 |
+
print("Skipped file_browser_manager.py")
|
| 102 |
+
return False
|
| 103 |
+
|
| 104 |
+
create_backup("file_browser_manager.py")
|
| 105 |
+
|
| 106 |
+
print("β
Ready to create file_browser_manager.py")
|
| 107 |
+
print(" Please copy the File Browser Manager artifact code")
|
| 108 |
+
return True
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
def update_app_gradio():
|
| 112 |
+
"""Update app_gradio.py with file browser integration."""
|
| 113 |
+
|
| 114 |
+
if not os.path.exists("app_gradio.py"):
|
| 115 |
+
print("β app_gradio.py not found!")
|
| 116 |
+
return False
|
| 117 |
+
|
| 118 |
+
# Backup existing
|
| 119 |
+
create_backup("app_gradio.py")
|
| 120 |
+
|
| 121 |
+
print("β
Backed up app_gradio.py")
|
| 122 |
+
print(" Please replace with updated version from artifacts")
|
| 123 |
+
|
| 124 |
+
return True
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
def show_post_deployment_instructions():
|
| 128 |
+
"""Show instructions after deployment."""
|
| 129 |
+
print("\n" + "=" * 60)
|
| 130 |
+
print("POST-DEPLOYMENT INSTRUCTIONS")
|
| 131 |
+
print("=" * 60)
|
| 132 |
+
print()
|
| 133 |
+
print("1. Copy file_browser_manager.py from the artifact")
|
| 134 |
+
print(" Save as: file_browser_manager.py")
|
| 135 |
+
print()
|
| 136 |
+
print("2. Copy updated app_gradio.py from the artifact")
|
| 137 |
+
print(" Save as: app_gradio.py (will replace existing)")
|
| 138 |
+
print()
|
| 139 |
+
print("3. Restart your application:")
|
| 140 |
+
print(" python app_gradio.py")
|
| 141 |
+
print()
|
| 142 |
+
print("4. Test the file browser:")
|
| 143 |
+
print(" - Generate some files")
|
| 144 |
+
print(" - Click the 'File Browser' tab")
|
| 145 |
+
print(" - Try downloading files")
|
| 146 |
+
print()
|
| 147 |
+
print("5. If issues occur, restore from backups/ directory")
|
| 148 |
+
print()
|
| 149 |
+
print("=" * 60)
|
| 150 |
+
|
| 151 |
+
|
| 152 |
+
def main():
|
| 153 |
+
"""Main deployment process."""
|
| 154 |
+
print("=" * 60)
|
| 155 |
+
print("FILE BROWSER INTEGRATION DEPLOYMENT")
|
| 156 |
+
print("=" * 60)
|
| 157 |
+
print()
|
| 158 |
+
print("This will:")
|
| 159 |
+
print(" 1. Create required directories")
|
| 160 |
+
print(" 2. Backup existing files")
|
| 161 |
+
print(" 3. Guide you through integration")
|
| 162 |
+
print()
|
| 163 |
+
|
| 164 |
+
response = input("Continue? (y/n): ")
|
| 165 |
+
if response.lower() != 'y':
|
| 166 |
+
print("Deployment cancelled.")
|
| 167 |
+
return
|
| 168 |
+
|
| 169 |
+
# Step 1: Create directories
|
| 170 |
+
create_required_directories()
|
| 171 |
+
|
| 172 |
+
# Step 2: Prepare file browser module
|
| 173 |
+
create_file_browser_module()
|
| 174 |
+
|
| 175 |
+
# Step 3: Update app_gradio
|
| 176 |
+
update_app_gradio()
|
| 177 |
+
|
| 178 |
+
# Step 4: Validate
|
| 179 |
+
validate_deployment()
|
| 180 |
+
|
| 181 |
+
# Step 5: Show instructions
|
| 182 |
+
show_post_deployment_instructions()
|
| 183 |
+
|
| 184 |
+
print("β
Deployment preparation complete!")
|
| 185 |
+
print()
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
if __name__ == "__main__":
|
| 189 |
+
main()
|