bytedance-1 / create_test_session.py
drdata's picture
Upload folder using huggingface_hub
e993e6d verified
raw
history blame
3.4 kB
#!/usr/bin/env python3
"""
Test script to verify view_session functionality
"""
import os
import shutil
from pathlib import Path
from PIL import Image
import io
def create_test_session():
"""Create a test session with sample images for testing view_session"""
print("πŸ§ͺ Creating test session for view_session testing...")
# Change to cache directory
cache_dir = Path(".cache")
if not cache_dir.exists():
print("❌ .cache directory not found. Run 'python app.py' first.")
return False
os.chdir(cache_dir)
# Create Generated directory if it doesn't exist
generated_dir = Path("Generated")
generated_dir.mkdir(exist_ok=True)
# Create test session directory
test_timestamp = "20250924_090627" # Same as your example
session_dir = generated_dir / f"session_{test_timestamp}"
# Remove existing test session if it exists
if session_dir.exists():
shutil.rmtree(session_dir)
session_dir.mkdir(exist_ok=True)
print(f"βœ… Created test session directory: {session_dir}")
# Create sample images
test_images = [
("generated_realistic_20250924_090627.jpg", (512, 512, 'red')),
("generated_artistic_20250924_090627.jpg", (512, 512, 'blue')),
("generated_vintage_20250924_090627.jpg", (512, 512, 'green')),
("webcam_input_20250924_090627.jpg", (512, 512, 'yellow'))
]
for filename, (width, height, color) in test_images:
try:
# Create a simple colored image
if color == 'red':
img = Image.new('RGB', (width, height), (255, 100, 100))
elif color == 'blue':
img = Image.new('RGB', (width, height), (100, 100, 255))
elif color == 'green':
img = Image.new('RGB', (width, height), (100, 255, 100))
else: # yellow
img = Image.new('RGB', (width, height), (255, 255, 100))
# Add some text to identify the image
from PIL import ImageDraw, ImageFont
draw = ImageDraw.Draw(img)
try:
# Try to use a better font, fallback to default if not available
font = ImageFont.truetype("/System/Library/Fonts/Arial.ttf", 24)
except:
font = ImageFont.load_default()
style_name = filename.replace('.jpg', '').replace(f'_{test_timestamp}', '').replace('generated_', '').replace('webcam_input', 'Input').title()
draw.text((50, 50), f"{style_name}\nTest Image", fill='white', font=font)
draw.text((50, 400), f"{filename}", fill='white', font=font)
# Save the image
img_path = session_dir / filename
img.save(img_path, 'JPEG', quality=90)
print(f"βœ… Created test image: {filename}")
except Exception as e:
print(f"❌ Failed to create {filename}: {e}")
print(f"\n🎯 Test session created successfully!")
print(f"πŸ“ Session directory: {session_dir.absolute()}")
print(f"🌐 Test URL: http://localhost:7860/view_session/{test_timestamp}")
print(f"πŸ“ Files created: {len(list(session_dir.glob('*.jpg')))} images")
# Go back to main directory
os.chdir("..")
return True
if __name__ == "__main__":
create_test_session()