Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- APP_PERMISSION_CHANGES.md +111 -0
- VIEW_SESSION_FIX_SUMMARY.md +112 -0
- __pycache__/app.cpython-310.pyc +0 -0
- app_security.log +6 -0
- create_test_session.py +91 -0
- open_test_in_browser.py +51 -0
- test_permissions.py +83 -0
- test_view_session.py +71 -0
APP_PERMISSION_CHANGES.md
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# App.py Permission Fix Summary
|
| 2 |
+
|
| 3 |
+
## β
Successfully Modified app.py for Directory Permissions
|
| 4 |
+
|
| 5 |
+
The BytePlus Image Generation Studio app.py has been modified to automatically set correct permissions (755) for the target directories and their subfolders.
|
| 6 |
+
|
| 7 |
+
## π§ Changes Made
|
| 8 |
+
|
| 9 |
+
### 1. Added Helper Function
|
| 10 |
+
**Location**: After line 54 (after security constants)
|
| 11 |
+
|
| 12 |
+
```python
|
| 13 |
+
def create_directory_with_permissions(directory_path, permissions=0o755):
|
| 14 |
+
"""
|
| 15 |
+
Create directory with proper permissions for Generated, static, and view_session folders
|
| 16 |
+
|
| 17 |
+
Args:
|
| 18 |
+
directory_path: Path to the directory to create
|
| 19 |
+
permissions: Permission bits (default: 755 - rwxr-xr-x)
|
| 20 |
+
"""
|
| 21 |
+
try:
|
| 22 |
+
os.makedirs(directory_path, exist_ok=True)
|
| 23 |
+
# Set permissions specifically for our target directories
|
| 24 |
+
if any(target in str(directory_path) for target in ['Generated', 'static', 'view_session']):
|
| 25 |
+
os.chmod(directory_path, permissions)
|
| 26 |
+
logger.info(f"Created directory with permissions {oct(permissions)}: {directory_path}")
|
| 27 |
+
except Exception as e:
|
| 28 |
+
logger.error(f"Failed to create directory {directory_path}: {str(e)}")
|
| 29 |
+
# Fallback to regular mkdir if chmod fails
|
| 30 |
+
os.makedirs(directory_path, exist_ok=True)
|
| 31 |
+
```
|
| 32 |
+
|
| 33 |
+
### 2. Modified Directory Creation Calls
|
| 34 |
+
|
| 35 |
+
#### Session and Generated directories (around line 1505):
|
| 36 |
+
**Before:**
|
| 37 |
+
```python
|
| 38 |
+
os.makedirs(session_dir, exist_ok=True)
|
| 39 |
+
os.makedirs(generated_dir, exist_ok=True)
|
| 40 |
+
```
|
| 41 |
+
**After:**
|
| 42 |
+
```python
|
| 43 |
+
create_directory_with_permissions(session_dir)
|
| 44 |
+
create_directory_with_permissions(generated_dir)
|
| 45 |
+
```
|
| 46 |
+
|
| 47 |
+
#### Static directory (around line 1590):
|
| 48 |
+
**Before:**
|
| 49 |
+
```python
|
| 50 |
+
os.makedirs(static_dir, exist_ok=True)
|
| 51 |
+
```
|
| 52 |
+
**After:**
|
| 53 |
+
```python
|
| 54 |
+
create_directory_with_permissions(static_dir)
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
#### Main startup directories (around line 1988):
|
| 58 |
+
**Before:**
|
| 59 |
+
```python
|
| 60 |
+
os.makedirs("Generated", exist_ok=True)
|
| 61 |
+
```
|
| 62 |
+
**After:**
|
| 63 |
+
```python
|
| 64 |
+
create_directory_with_permissions("Generated")
|
| 65 |
+
create_directory_with_permissions("static")
|
| 66 |
+
create_directory_with_permissions("view_session")
|
| 67 |
+
```
|
| 68 |
+
|
| 69 |
+
## π― What This Achieves
|
| 70 |
+
|
| 71 |
+
1. **Automatic Permission Setting**: All target directories are created with 755 permissions (rwxr-xr-x)
|
| 72 |
+
2. **Consistent Behavior**: Works for all directory creation scenarios:
|
| 73 |
+
- App startup
|
| 74 |
+
- Session folder creation during image generation
|
| 75 |
+
- Static folder creation for ZIP downloads
|
| 76 |
+
3. **Error Handling**: Falls back to regular mkdir if permission setting fails
|
| 77 |
+
4. **Logging**: Logs when directories are created with special permissions
|
| 78 |
+
5. **Targeted**: Only affects the specific directories you care about
|
| 79 |
+
|
| 80 |
+
## π§ͺ Tested and Verified
|
| 81 |
+
|
| 82 |
+
- β
Function import test passed
|
| 83 |
+
- β
Directory creation with correct permissions confirmed
|
| 84 |
+
- β
App startup creates all directories with 755 permissions
|
| 85 |
+
- β
Logging shows permission setting is working
|
| 86 |
+
|
| 87 |
+
## π Directory Permissions Set
|
| 88 |
+
|
| 89 |
+
- **Generated/**: 755 (rwxr-xr-x) - For generated image storage
|
| 90 |
+
- **static/**: 755 (rwxr-xr-x) - For ZIP download files
|
| 91 |
+
- **view_session/**: 755 (rwxr-xr-x) - For session viewer functionality
|
| 92 |
+
- **All session subfolders**: 755 (rwxr-xr-x) - For individual session images
|
| 93 |
+
|
| 94 |
+
## π Usage
|
| 95 |
+
|
| 96 |
+
The modified app.py now automatically handles permissions. Simply run:
|
| 97 |
+
|
| 98 |
+
```bash
|
| 99 |
+
cd .cache
|
| 100 |
+
python app.py
|
| 101 |
+
```
|
| 102 |
+
|
| 103 |
+
And all directories will be created with the correct 755 permissions, making them accessible while maintaining security.
|
| 104 |
+
|
| 105 |
+
## π Benefits
|
| 106 |
+
|
| 107 |
+
- **No Manual Intervention**: Permissions are set automatically
|
| 108 |
+
- **Persistent**: Works every time the app runs
|
| 109 |
+
- **Safe**: Only affects the specific target directories
|
| 110 |
+
- **Maintained**: Preserves all original app functionality
|
| 111 |
+
- **Logged**: Permission changes are logged for transparency
|
VIEW_SESSION_FIX_SUMMARY.md
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# View Session Fix Summary
|
| 2 |
+
|
| 3 |
+
## β
Problem Resolved!
|
| 4 |
+
|
| 5 |
+
The view_session functionality in the BytePlus Image Generation Studio has been fixed and is now working correctly.
|
| 6 |
+
|
| 7 |
+
## π Issues That Were Fixed
|
| 8 |
+
|
| 9 |
+
### 1. **Route Implementation**
|
| 10 |
+
- **Problem**: The `/view_session/{timestamp}` route was missing proper error handling
|
| 11 |
+
- **Fix**: Added comprehensive error handling for missing sessions and files
|
| 12 |
+
|
| 13 |
+
### 2. **File URL Generation**
|
| 14 |
+
- **Problem**: Image URLs were incorrectly formatted
|
| 15 |
+
- **Fix**: Corrected URLs to use `/files/session_{timestamp}/{filename}` format
|
| 16 |
+
|
| 17 |
+
### 3. **HTML Page Generation**
|
| 18 |
+
- **Problem**: Basic HTML with poor error handling and styling
|
| 19 |
+
- **Fix**: Enhanced HTML with:
|
| 20 |
+
- Modern responsive design
|
| 21 |
+
- Better error handling with user-friendly messages
|
| 22 |
+
- Improved image display with hover effects
|
| 23 |
+
- Proper error messaging for failed image loads
|
| 24 |
+
|
| 25 |
+
### 4. **File Serving**
|
| 26 |
+
- **Problem**: Static file mounting might not work correctly
|
| 27 |
+
- **Fix**: Verified `/files/` mount point works with `Generated/` directory
|
| 28 |
+
|
| 29 |
+
## π§ Technical Changes Made
|
| 30 |
+
|
| 31 |
+
### Enhanced Route Handler
|
| 32 |
+
```python
|
| 33 |
+
@app.get("/view_session/{timestamp}")
|
| 34 |
+
async def view_session(timestamp: str):
|
| 35 |
+
# Added comprehensive error handling
|
| 36 |
+
# Enhanced HTML generation
|
| 37 |
+
# Improved image URL formatting
|
| 38 |
+
```
|
| 39 |
+
|
| 40 |
+
### Key Improvements:
|
| 41 |
+
- β
**Error Handling**: Proper 404 handling for missing sessions
|
| 42 |
+
- β
**Image Support**: Support for .jpg, .jpeg, .png files
|
| 43 |
+
- β
**Modern UI**: Responsive design with hover effects
|
| 44 |
+
- β
**Error Messages**: User-friendly error messages
|
| 45 |
+
- β
**File Validation**: Checks for session existence and image availability
|
| 46 |
+
|
| 47 |
+
## π§ͺ Testing Performed
|
| 48 |
+
|
| 49 |
+
### Automated Tests β
|
| 50 |
+
- Route accessibility test: **PASSED**
|
| 51 |
+
- HTML content validation: **PASSED**
|
| 52 |
+
- Image URL generation: **PASSED**
|
| 53 |
+
- Direct file access: **PASSED**
|
| 54 |
+
- Found all expected images: **PASSED**
|
| 55 |
+
|
| 56 |
+
### Test Session Created
|
| 57 |
+
- **Session ID**: `20250924_090627`
|
| 58 |
+
- **Location**: `.cache/Generated/session_20250924_090627/`
|
| 59 |
+
- **Images**: 4 test images with different styles
|
| 60 |
+
- **Test URL**: `http://localhost:7860/view_session/20250924_090627`
|
| 61 |
+
|
| 62 |
+
## π How to Test
|
| 63 |
+
|
| 64 |
+
### 1. Using the Test Session
|
| 65 |
+
```bash
|
| 66 |
+
# The app should be running at http://localhost:7860
|
| 67 |
+
# Visit: http://localhost:7860/view_session/20250924_090627
|
| 68 |
+
```
|
| 69 |
+
|
| 70 |
+
### 2. Generate New Session
|
| 71 |
+
1. Use the BytePlus app to generate some images
|
| 72 |
+
2. Check the history gallery for session folders
|
| 73 |
+
3. Click the "ποΈ View" button next to any session
|
| 74 |
+
|
| 75 |
+
### 3. Expected Behavior
|
| 76 |
+
- β
Opens in new tab/window
|
| 77 |
+
- β
Shows session timestamp and image count
|
| 78 |
+
- β
Displays all images in a responsive grid
|
| 79 |
+
- β
Images are clickable to open in full size
|
| 80 |
+
- β
Shows proper error messages if session/images missing
|
| 81 |
+
|
| 82 |
+
## π± Features of Fixed View Session
|
| 83 |
+
|
| 84 |
+
### Visual Improvements
|
| 85 |
+
- **Modern Design**: Clean, card-based layout
|
| 86 |
+
- **Responsive Grid**: Adapts to different screen sizes
|
| 87 |
+
- **Hover Effects**: Smooth animations on image hover
|
| 88 |
+
- **Typography**: Better fonts and spacing
|
| 89 |
+
|
| 90 |
+
### Functionality
|
| 91 |
+
- **Image Preview**: Click any image to open full-size
|
| 92 |
+
- **Session Info**: Shows generation date and image count
|
| 93 |
+
- **Error Handling**: Graceful error messages for issues
|
| 94 |
+
- **Close Button**: Easy way to close the viewer
|
| 95 |
+
|
| 96 |
+
### Accessibility
|
| 97 |
+
- **Mobile Friendly**: Works on mobile devices
|
| 98 |
+
- **Fast Loading**: Optimized image loading
|
| 99 |
+
- **Error Recovery**: Shows specific error messages
|
| 100 |
+
- **Navigation**: Clear navigation options
|
| 101 |
+
|
| 102 |
+
## π Ready to Use!
|
| 103 |
+
|
| 104 |
+
The view_session functionality is now fully operational. When you:
|
| 105 |
+
|
| 106 |
+
1. **Generate images** in the BytePlus app
|
| 107 |
+
2. **View the history** in the gallery
|
| 108 |
+
3. **Click "ποΈ View"** next to any session
|
| 109 |
+
|
| 110 |
+
You will now see a beautiful, functional image gallery showing all generated images from that session! π¨
|
| 111 |
+
|
| 112 |
+
The issue with redirecting to the HuggingFace URL and showing nothing has been completely resolved.
|
__pycache__/app.cpython-310.pyc
CHANGED
|
Binary files a/__pycache__/app.cpython-310.pyc and b/__pycache__/app.cpython-310.pyc differ
|
|
|
app_security.log
CHANGED
|
@@ -10,3 +10,9 @@
|
|
| 10 |
2025-09-24 14:58:07,144 - httpx - INFO - HTTP Request: GET http://127.0.0.1:7860/gradio_api/startup-events "HTTP/1.1 200 OK"
|
| 11 |
2025-09-24 14:58:07,220 - httpx - INFO - HTTP Request: HEAD http://127.0.0.1:7860/ "HTTP/1.1 200 OK"
|
| 12 |
2025-09-24 14:58:07,761 - httpx - INFO - HTTP Request: GET https://api.gradio.app/pkg-version "HTTP/1.1 200 OK"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
2025-09-24 14:58:07,144 - httpx - INFO - HTTP Request: GET http://127.0.0.1:7860/gradio_api/startup-events "HTTP/1.1 200 OK"
|
| 11 |
2025-09-24 14:58:07,220 - httpx - INFO - HTTP Request: HEAD http://127.0.0.1:7860/ "HTTP/1.1 200 OK"
|
| 12 |
2025-09-24 14:58:07,761 - httpx - INFO - HTTP Request: GET https://api.gradio.app/pkg-version "HTTP/1.1 200 OK"
|
| 13 |
+
2025-09-24 15:28:36,439 - httpx - INFO - HTTP Request: GET http://127.0.0.1:7860/gradio_api/startup-events "HTTP/1.1 200 OK"
|
| 14 |
+
2025-09-24 15:28:36,514 - httpx - INFO - HTTP Request: HEAD http://127.0.0.1:7860/ "HTTP/1.1 200 OK"
|
| 15 |
+
2025-09-24 15:28:36,928 - httpx - INFO - HTTP Request: GET https://api.gradio.app/pkg-version "HTTP/1.1 200 OK"
|
| 16 |
+
2025-09-24 15:31:28,704 - app - INFO - Created directory with permissions 0o755: Generated
|
| 17 |
+
2025-09-24 15:31:28,704 - app - INFO - Created directory with permissions 0o755: static
|
| 18 |
+
2025-09-24 15:31:28,704 - app - INFO - Created directory with permissions 0o755: view_session
|
create_test_session.py
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Test script to verify view_session functionality
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import os
|
| 7 |
+
import shutil
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
from PIL import Image
|
| 10 |
+
import io
|
| 11 |
+
|
| 12 |
+
def create_test_session():
|
| 13 |
+
"""Create a test session with sample images for testing view_session"""
|
| 14 |
+
|
| 15 |
+
print("π§ͺ Creating test session for view_session testing...")
|
| 16 |
+
|
| 17 |
+
# Change to cache directory
|
| 18 |
+
cache_dir = Path(".cache")
|
| 19 |
+
if not cache_dir.exists():
|
| 20 |
+
print("β .cache directory not found. Run 'python app.py' first.")
|
| 21 |
+
return False
|
| 22 |
+
|
| 23 |
+
os.chdir(cache_dir)
|
| 24 |
+
|
| 25 |
+
# Create Generated directory if it doesn't exist
|
| 26 |
+
generated_dir = Path("Generated")
|
| 27 |
+
generated_dir.mkdir(exist_ok=True)
|
| 28 |
+
|
| 29 |
+
# Create test session directory
|
| 30 |
+
test_timestamp = "20250924_090627" # Same as your example
|
| 31 |
+
session_dir = generated_dir / f"session_{test_timestamp}"
|
| 32 |
+
|
| 33 |
+
# Remove existing test session if it exists
|
| 34 |
+
if session_dir.exists():
|
| 35 |
+
shutil.rmtree(session_dir)
|
| 36 |
+
|
| 37 |
+
session_dir.mkdir(exist_ok=True)
|
| 38 |
+
print(f"β
Created test session directory: {session_dir}")
|
| 39 |
+
|
| 40 |
+
# Create sample images
|
| 41 |
+
test_images = [
|
| 42 |
+
("generated_realistic_20250924_090627.jpg", (512, 512, 'red')),
|
| 43 |
+
("generated_artistic_20250924_090627.jpg", (512, 512, 'blue')),
|
| 44 |
+
("generated_vintage_20250924_090627.jpg", (512, 512, 'green')),
|
| 45 |
+
("webcam_input_20250924_090627.jpg", (512, 512, 'yellow'))
|
| 46 |
+
]
|
| 47 |
+
|
| 48 |
+
for filename, (width, height, color) in test_images:
|
| 49 |
+
try:
|
| 50 |
+
# Create a simple colored image
|
| 51 |
+
if color == 'red':
|
| 52 |
+
img = Image.new('RGB', (width, height), (255, 100, 100))
|
| 53 |
+
elif color == 'blue':
|
| 54 |
+
img = Image.new('RGB', (width, height), (100, 100, 255))
|
| 55 |
+
elif color == 'green':
|
| 56 |
+
img = Image.new('RGB', (width, height), (100, 255, 100))
|
| 57 |
+
else: # yellow
|
| 58 |
+
img = Image.new('RGB', (width, height), (255, 255, 100))
|
| 59 |
+
|
| 60 |
+
# Add some text to identify the image
|
| 61 |
+
from PIL import ImageDraw, ImageFont
|
| 62 |
+
draw = ImageDraw.Draw(img)
|
| 63 |
+
try:
|
| 64 |
+
# Try to use a better font, fallback to default if not available
|
| 65 |
+
font = ImageFont.truetype("/System/Library/Fonts/Arial.ttf", 24)
|
| 66 |
+
except:
|
| 67 |
+
font = ImageFont.load_default()
|
| 68 |
+
|
| 69 |
+
style_name = filename.replace('.jpg', '').replace(f'_{test_timestamp}', '').replace('generated_', '').replace('webcam_input', 'Input').title()
|
| 70 |
+
draw.text((50, 50), f"{style_name}\nTest Image", fill='white', font=font)
|
| 71 |
+
draw.text((50, 400), f"{filename}", fill='white', font=font)
|
| 72 |
+
|
| 73 |
+
# Save the image
|
| 74 |
+
img_path = session_dir / filename
|
| 75 |
+
img.save(img_path, 'JPEG', quality=90)
|
| 76 |
+
print(f"β
Created test image: {filename}")
|
| 77 |
+
|
| 78 |
+
except Exception as e:
|
| 79 |
+
print(f"β Failed to create {filename}: {e}")
|
| 80 |
+
|
| 81 |
+
print(f"\nπ― Test session created successfully!")
|
| 82 |
+
print(f"π Session directory: {session_dir.absolute()}")
|
| 83 |
+
print(f"π Test URL: http://localhost:7860/view_session/{test_timestamp}")
|
| 84 |
+
print(f"π Files created: {len(list(session_dir.glob('*.jpg')))} images")
|
| 85 |
+
|
| 86 |
+
# Go back to main directory
|
| 87 |
+
os.chdir("..")
|
| 88 |
+
return True
|
| 89 |
+
|
| 90 |
+
if __name__ == "__main__":
|
| 91 |
+
create_test_session()
|
open_test_in_browser.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Open the test view_session page in browser for visual testing
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import webbrowser
|
| 7 |
+
import time
|
| 8 |
+
import requests
|
| 9 |
+
|
| 10 |
+
def open_view_session_test():
|
| 11 |
+
"""Open the view_session test page in the default browser"""
|
| 12 |
+
|
| 13 |
+
print("π Opening view_session test in browser...")
|
| 14 |
+
|
| 15 |
+
# Check if server is running
|
| 16 |
+
base_url = "http://localhost:7860"
|
| 17 |
+
test_timestamp = "20250924_090627"
|
| 18 |
+
test_url = f"{base_url}/view_session/{test_timestamp}"
|
| 19 |
+
|
| 20 |
+
try:
|
| 21 |
+
# Quick check if server is responding
|
| 22 |
+
response = requests.get(base_url, timeout=3)
|
| 23 |
+
print("β
Server is running!")
|
| 24 |
+
|
| 25 |
+
# Open the view_session page
|
| 26 |
+
print(f"π Opening: {test_url}")
|
| 27 |
+
webbrowser.open(test_url)
|
| 28 |
+
|
| 29 |
+
print("\nπ What you should see:")
|
| 30 |
+
print("β
A modern, responsive image gallery")
|
| 31 |
+
print("β
Session timestamp: September 24, 2025 at 09:06:27")
|
| 32 |
+
print("β
4 test images in a grid layout")
|
| 33 |
+
print("β
Images with labels: Realistic, Artistic, Vintage, Input")
|
| 34 |
+
print("β
Clickable images that open full-size")
|
| 35 |
+
print("β
Modern styling with hover effects")
|
| 36 |
+
|
| 37 |
+
print("\nπ§ͺ Also test these URLs:")
|
| 38 |
+
print(f"π± Main app: {base_url}")
|
| 39 |
+
print(f"π Direct file: {base_url}/files/session_{test_timestamp}/generated_realistic_{test_timestamp}.jpg")
|
| 40 |
+
print(f"π₯ Generated folder: {base_url}/Generated/")
|
| 41 |
+
|
| 42 |
+
except requests.exceptions.ConnectionError:
|
| 43 |
+
print("β Server is not running!")
|
| 44 |
+
print("π‘ Start the server first:")
|
| 45 |
+
print(" cd .cache && python app.py")
|
| 46 |
+
|
| 47 |
+
except Exception as e:
|
| 48 |
+
print(f"β Error: {e}")
|
| 49 |
+
|
| 50 |
+
if __name__ == "__main__":
|
| 51 |
+
open_view_session_test()
|
test_permissions.py
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Test script to verify directory permissions are set correctly in app.py
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import os
|
| 7 |
+
import sys
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
|
| 10 |
+
def test_directory_permissions():
|
| 11 |
+
"""Test that directories are created with correct permissions"""
|
| 12 |
+
|
| 13 |
+
print("π§ͺ Testing Directory Permission Setup in app.py")
|
| 14 |
+
print("=" * 50)
|
| 15 |
+
|
| 16 |
+
# Change to cache directory where the modified app.py is located
|
| 17 |
+
cache_dir = Path(".cache")
|
| 18 |
+
if not cache_dir.exists():
|
| 19 |
+
print("β .cache directory not found. Run 'python app.py' first.")
|
| 20 |
+
return False
|
| 21 |
+
|
| 22 |
+
# Import and test the function from the modified app in .cache
|
| 23 |
+
sys.path.insert(0, str(cache_dir.absolute()))
|
| 24 |
+
|
| 25 |
+
try:
|
| 26 |
+
import app
|
| 27 |
+
from app import create_directory_with_permissions
|
| 28 |
+
print("β
Successfully imported create_directory_with_permissions function")
|
| 29 |
+
except ImportError as e:
|
| 30 |
+
print(f"β Failed to import function: {e}")
|
| 31 |
+
return False
|
| 32 |
+
|
| 33 |
+
# Change to cache directory for testing
|
| 34 |
+
original_dir = Path.cwd()
|
| 35 |
+
os.chdir(cache_dir)
|
| 36 |
+
|
| 37 |
+
# Test directories
|
| 38 |
+
test_dirs = ["Generated", "static", "view_session", "test_session_123"]
|
| 39 |
+
|
| 40 |
+
print("\nπ Testing directory creation and permissions:")
|
| 41 |
+
print("-" * 40)
|
| 42 |
+
|
| 43 |
+
for dir_name in test_dirs:
|
| 44 |
+
try:
|
| 45 |
+
# Remove directory if it exists (for clean test)
|
| 46 |
+
if Path(dir_name).exists():
|
| 47 |
+
import shutil
|
| 48 |
+
shutil.rmtree(dir_name)
|
| 49 |
+
|
| 50 |
+
# Create directory using our function
|
| 51 |
+
create_directory_with_permissions(dir_name)
|
| 52 |
+
|
| 53 |
+
# Check if directory exists
|
| 54 |
+
if Path(dir_name).exists():
|
| 55 |
+
# Check permissions
|
| 56 |
+
stat_info = Path(dir_name).stat()
|
| 57 |
+
permissions = oct(stat_info.st_mode)[-3:]
|
| 58 |
+
expected_perm = "755"
|
| 59 |
+
|
| 60 |
+
if permissions == expected_perm:
|
| 61 |
+
print(f"β
{dir_name:15} - Created with correct permissions ({permissions})")
|
| 62 |
+
else:
|
| 63 |
+
print(f"β οΈ {dir_name:15} - Created with permissions ({permissions}), expected ({expected_perm})")
|
| 64 |
+
else:
|
| 65 |
+
print(f"β {dir_name:15} - Failed to create")
|
| 66 |
+
|
| 67 |
+
except Exception as e:
|
| 68 |
+
print(f"β {dir_name:15} - Error: {e}")
|
| 69 |
+
|
| 70 |
+
print("\n" + "=" * 50)
|
| 71 |
+
print("β
Permission test completed!")
|
| 72 |
+
print("π‘ The app.py now automatically sets correct permissions for:")
|
| 73 |
+
print(" - Generated/ (and all session subfolders)")
|
| 74 |
+
print(" - static/")
|
| 75 |
+
print(" - view_session/")
|
| 76 |
+
|
| 77 |
+
# Return to original directory
|
| 78 |
+
os.chdir(original_dir)
|
| 79 |
+
|
| 80 |
+
return True
|
| 81 |
+
|
| 82 |
+
if __name__ == "__main__":
|
| 83 |
+
test_directory_permissions()
|
test_view_session.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Test the view_session route directly
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import requests
|
| 7 |
+
import time
|
| 8 |
+
|
| 9 |
+
def test_view_session_route():
|
| 10 |
+
"""Test the view_session route"""
|
| 11 |
+
print("π§ͺ Testing view_session route...")
|
| 12 |
+
|
| 13 |
+
# Give the server a moment to fully start
|
| 14 |
+
time.sleep(2)
|
| 15 |
+
|
| 16 |
+
base_url = "http://localhost:7860"
|
| 17 |
+
test_timestamp = "20250924_090627"
|
| 18 |
+
test_url = f"{base_url}/view_session/{test_timestamp}"
|
| 19 |
+
|
| 20 |
+
try:
|
| 21 |
+
print(f"π‘ Testing URL: {test_url}")
|
| 22 |
+
response = requests.get(test_url, timeout=10)
|
| 23 |
+
|
| 24 |
+
print(f"π Response Status: {response.status_code}")
|
| 25 |
+
print(f"π Content-Type: {response.headers.get('content-type', 'Not specified')}")
|
| 26 |
+
print(f"π Content Length: {len(response.text)} characters")
|
| 27 |
+
|
| 28 |
+
if response.status_code == 200:
|
| 29 |
+
if "Session 20250924_090627" in response.text:
|
| 30 |
+
print("β
SUCCESS: View session page loaded correctly!")
|
| 31 |
+
|
| 32 |
+
# Check if images are referenced
|
| 33 |
+
if "/files/session_20250924_090627/" in response.text:
|
| 34 |
+
print("β
SUCCESS: Image URLs are properly generated!")
|
| 35 |
+
else:
|
| 36 |
+
print("β οΈ WARNING: Image URLs might be missing")
|
| 37 |
+
|
| 38 |
+
# Check for expected images
|
| 39 |
+
expected_images = ["realistic", "artistic", "vintage", "webcam"]
|
| 40 |
+
found_images = [img for img in expected_images if img.lower() in response.text.lower()]
|
| 41 |
+
print(f"πΌοΈ Found image references: {found_images}")
|
| 42 |
+
|
| 43 |
+
else:
|
| 44 |
+
print("β οΈ WARNING: Expected content not found in response")
|
| 45 |
+
|
| 46 |
+
elif response.status_code == 404:
|
| 47 |
+
print("β ERROR: Session not found (404)")
|
| 48 |
+
else:
|
| 49 |
+
print(f"β ERROR: Unexpected status code: {response.status_code}")
|
| 50 |
+
|
| 51 |
+
# Test a file URL directly
|
| 52 |
+
file_test_url = f"{base_url}/files/session_{test_timestamp}/generated_realistic_{test_timestamp}.jpg"
|
| 53 |
+
print(f"\nπ‘ Testing direct file access: {file_test_url}")
|
| 54 |
+
|
| 55 |
+
file_response = requests.head(file_test_url, timeout=5)
|
| 56 |
+
print(f"π File Response Status: {file_response.status_code}")
|
| 57 |
+
|
| 58 |
+
if file_response.status_code == 200:
|
| 59 |
+
print("β
SUCCESS: Direct file access works!")
|
| 60 |
+
else:
|
| 61 |
+
print(f"β ERROR: Direct file access failed: {file_response.status_code}")
|
| 62 |
+
|
| 63 |
+
except requests.exceptions.ConnectionError:
|
| 64 |
+
print("β ERROR: Could not connect to the server. Is the app running?")
|
| 65 |
+
except requests.exceptions.Timeout:
|
| 66 |
+
print("β ERROR: Request timed out")
|
| 67 |
+
except Exception as e:
|
| 68 |
+
print(f"β ERROR: {e}")
|
| 69 |
+
|
| 70 |
+
if __name__ == "__main__":
|
| 71 |
+
test_view_session_route()
|