Spaces:
Running
Running
Delete capture_docs_screenshots.py
Browse files- capture_docs_screenshots.py +0 -331
capture_docs_screenshots.py
DELETED
|
@@ -1,331 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
Specialized screenshot capture for documentation steps in support_docs.py
|
| 3 |
-
Captures specific HuggingFace Spaces deployment screenshots
|
| 4 |
-
"""
|
| 5 |
-
|
| 6 |
-
import asyncio
|
| 7 |
-
import os
|
| 8 |
-
from pathlib import Path
|
| 9 |
-
from playwright.async_api import async_playwright
|
| 10 |
-
import logging
|
| 11 |
-
import json
|
| 12 |
-
from datetime import datetime
|
| 13 |
-
|
| 14 |
-
# Configure logging
|
| 15 |
-
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(message)s')
|
| 16 |
-
logger = logging.getLogger(__name__)
|
| 17 |
-
|
| 18 |
-
# Documentation-specific screenshot configurations
|
| 19 |
-
DOCS_SCREENSHOTS = {
|
| 20 |
-
# Step 1: Generate & Create Space
|
| 21 |
-
"huggingface_spaces_page": {
|
| 22 |
-
"url": "https://huggingface.co/spaces",
|
| 23 |
-
"description": "HuggingFace Spaces main page",
|
| 24 |
-
"output": "img/hf_spaces_main.png",
|
| 25 |
-
"actions": [],
|
| 26 |
-
"wait_time": 3000
|
| 27 |
-
},
|
| 28 |
-
"new_space_button": {
|
| 29 |
-
"url": "https://huggingface.co/spaces",
|
| 30 |
-
"description": "New Space button",
|
| 31 |
-
"output": "img/hf_new_space_button.png",
|
| 32 |
-
"actions": [],
|
| 33 |
-
"selector": "button:has-text('New Space')",
|
| 34 |
-
"wait_time": 2000
|
| 35 |
-
},
|
| 36 |
-
"space_creation_form": {
|
| 37 |
-
"url": "https://huggingface.co/new-space",
|
| 38 |
-
"description": "Space creation form (img17.png replacement)",
|
| 39 |
-
"output": "img/img17.png",
|
| 40 |
-
"actions": [],
|
| 41 |
-
"wait_time": 3000
|
| 42 |
-
},
|
| 43 |
-
"hardware_selection": {
|
| 44 |
-
"url": "https://huggingface.co/new-space",
|
| 45 |
-
"description": "Hardware selection options (img16.png replacement)",
|
| 46 |
-
"output": "img/img16.png",
|
| 47 |
-
"actions": [
|
| 48 |
-
{"type": "scroll", "y": 400}
|
| 49 |
-
],
|
| 50 |
-
"wait_time": 2000
|
| 51 |
-
},
|
| 52 |
-
|
| 53 |
-
# Step 2: Upload Files
|
| 54 |
-
"files_tab": {
|
| 55 |
-
"url": "https://huggingface.co/spaces/{username}/{space_name}/tree/main",
|
| 56 |
-
"description": "Files tab in Space",
|
| 57 |
-
"output": "img/hf_files_tab.png",
|
| 58 |
-
"actions": [],
|
| 59 |
-
"wait_time": 2000
|
| 60 |
-
},
|
| 61 |
-
"upload_files_button": {
|
| 62 |
-
"url": "https://huggingface.co/spaces/{username}/{space_name}/tree/main",
|
| 63 |
-
"description": "Upload files interface (img12.png replacement)",
|
| 64 |
-
"output": "img/img12.png",
|
| 65 |
-
"actions": [
|
| 66 |
-
{"type": "click", "selector": "button:has-text('Upload files')"}
|
| 67 |
-
],
|
| 68 |
-
"wait_time": 2000
|
| 69 |
-
},
|
| 70 |
-
"files_after_upload": {
|
| 71 |
-
"url": "https://huggingface.co/spaces/{username}/{space_name}/tree/main",
|
| 72 |
-
"description": "Files view after upload (img8.png replacement)",
|
| 73 |
-
"output": "img/img8.png",
|
| 74 |
-
"actions": [],
|
| 75 |
-
"wait_time": 2000
|
| 76 |
-
},
|
| 77 |
-
|
| 78 |
-
# Step 3: Configure API Secrets
|
| 79 |
-
"settings_tab": {
|
| 80 |
-
"url": "https://huggingface.co/spaces/{username}/{space_name}/settings",
|
| 81 |
-
"description": "Settings tab navigation (img4.png replacement)",
|
| 82 |
-
"output": "img/img4.png",
|
| 83 |
-
"actions": [],
|
| 84 |
-
"wait_time": 2000
|
| 85 |
-
},
|
| 86 |
-
"variables_secrets_section": {
|
| 87 |
-
"url": "https://huggingface.co/spaces/{username}/{space_name}/settings",
|
| 88 |
-
"description": "Variables and secrets section",
|
| 89 |
-
"output": "img/hf_variables_secrets.png",
|
| 90 |
-
"actions": [
|
| 91 |
-
{"type": "scroll", "y": 300}
|
| 92 |
-
],
|
| 93 |
-
"wait_time": 2000
|
| 94 |
-
},
|
| 95 |
-
"new_secret_form": {
|
| 96 |
-
"url": "https://huggingface.co/spaces/{username}/{space_name}/settings",
|
| 97 |
-
"description": "New secret configuration form (img3.png replacement)",
|
| 98 |
-
"output": "img/img3.png",
|
| 99 |
-
"actions": [
|
| 100 |
-
{"type": "click", "selector": "button:has-text('New secret')"}
|
| 101 |
-
],
|
| 102 |
-
"wait_time": 2000
|
| 103 |
-
},
|
| 104 |
-
|
| 105 |
-
# Step 4: Monitor Build
|
| 106 |
-
"build_logs": {
|
| 107 |
-
"url": "https://huggingface.co/spaces/{username}/{space_name}",
|
| 108 |
-
"description": "Build process logs (img7.png replacement)",
|
| 109 |
-
"output": "img/img7.png",
|
| 110 |
-
"actions": [],
|
| 111 |
-
"wait_time": 3000
|
| 112 |
-
},
|
| 113 |
-
"successful_deployment": {
|
| 114 |
-
"url": "https://huggingface.co/spaces/{username}/{space_name}",
|
| 115 |
-
"description": "Successfully deployed Space (img1.png replacement)",
|
| 116 |
-
"output": "img/img1.png",
|
| 117 |
-
"actions": [],
|
| 118 |
-
"wait_time": 5000
|
| 119 |
-
}
|
| 120 |
-
}
|
| 121 |
-
|
| 122 |
-
# Local app screenshots for main documentation
|
| 123 |
-
LOCAL_APP_SCREENSHOTS = {
|
| 124 |
-
"config_tab_full": {
|
| 125 |
-
"url": "http://localhost:7860",
|
| 126 |
-
"description": "Full configuration tab",
|
| 127 |
-
"output": "img/config_tab_full.png",
|
| 128 |
-
"actions": [
|
| 129 |
-
{"type": "click", "selector": "button:has-text('Configure Space')"}
|
| 130 |
-
],
|
| 131 |
-
"wait_time": 2000,
|
| 132 |
-
"full_page": True
|
| 133 |
-
},
|
| 134 |
-
"template_selection": {
|
| 135 |
-
"url": "http://localhost:7860",
|
| 136 |
-
"description": "Template selection with dropdown open",
|
| 137 |
-
"output": "img/template_selection.png",
|
| 138 |
-
"actions": [
|
| 139 |
-
{"type": "click", "selector": "button:has-text('Configure Space')"},
|
| 140 |
-
{"type": "wait", "time": 1000},
|
| 141 |
-
{"type": "click", "selector": "div.gr-dropdown"}
|
| 142 |
-
],
|
| 143 |
-
"wait_time": 1500
|
| 144 |
-
},
|
| 145 |
-
"space_identity_section": {
|
| 146 |
-
"url": "http://localhost:7860",
|
| 147 |
-
"description": "Space identity configuration",
|
| 148 |
-
"output": "img/space_identity_config.png",
|
| 149 |
-
"actions": [
|
| 150 |
-
{"type": "click", "selector": "button:has-text('Configure Space')"},
|
| 151 |
-
{"type": "scroll", "y": 200}
|
| 152 |
-
],
|
| 153 |
-
"wait_time": 1000
|
| 154 |
-
},
|
| 155 |
-
"system_config_section": {
|
| 156 |
-
"url": "http://localhost:7860",
|
| 157 |
-
"description": "System configuration section",
|
| 158 |
-
"output": "img/system_config_section.png",
|
| 159 |
-
"actions": [
|
| 160 |
-
{"type": "click", "selector": "button:has-text('Configure Space')"},
|
| 161 |
-
{"type": "scroll", "y": 600}
|
| 162 |
-
],
|
| 163 |
-
"wait_time": 1000
|
| 164 |
-
},
|
| 165 |
-
"api_config_section": {
|
| 166 |
-
"url": "http://localhost:7860",
|
| 167 |
-
"description": "API configuration section",
|
| 168 |
-
"output": "img/api_config_section.png",
|
| 169 |
-
"actions": [
|
| 170 |
-
{"type": "click", "selector": "button:has-text('Configure Space')"},
|
| 171 |
-
{"type": "scroll", "y": 1200}
|
| 172 |
-
],
|
| 173 |
-
"wait_time": 1000
|
| 174 |
-
},
|
| 175 |
-
"preview_tab_active": {
|
| 176 |
-
"url": "http://localhost:7860",
|
| 177 |
-
"description": "Preview tab with active chat",
|
| 178 |
-
"output": "img/preview_tab_active.png",
|
| 179 |
-
"actions": [
|
| 180 |
-
{"type": "click", "selector": "button:has-text('Preview')"},
|
| 181 |
-
{"type": "wait", "time": 2000},
|
| 182 |
-
{"type": "type", "selector": "textarea", "text": "Tell me about quantum mechanics"},
|
| 183 |
-
{"type": "click", "selector": "button:has-text('Send')"},
|
| 184 |
-
{"type": "wait", "time": 4000}
|
| 185 |
-
],
|
| 186 |
-
"wait_time": 1000
|
| 187 |
-
},
|
| 188 |
-
"docs_tab_overview": {
|
| 189 |
-
"url": "http://localhost:7860",
|
| 190 |
-
"description": "Documentation tab overview",
|
| 191 |
-
"output": "img/docs_tab_overview.png",
|
| 192 |
-
"actions": [
|
| 193 |
-
{"type": "click", "selector": "button:has-text('Docs')"}
|
| 194 |
-
],
|
| 195 |
-
"wait_time": 2000
|
| 196 |
-
},
|
| 197 |
-
"docs_deployment_steps": {
|
| 198 |
-
"url": "http://localhost:7860",
|
| 199 |
-
"description": "Deployment steps accordion expanded",
|
| 200 |
-
"output": "img/docs_deployment_steps.png",
|
| 201 |
-
"actions": [
|
| 202 |
-
{"type": "click", "selector": "button:has-text('Docs')"},
|
| 203 |
-
{"type": "wait", "time": 1000},
|
| 204 |
-
{"type": "click", "selector": "button:has-text('🗳️ Step 3: Generate & Deploy')"}
|
| 205 |
-
],
|
| 206 |
-
"wait_time": 2000
|
| 207 |
-
}
|
| 208 |
-
}
|
| 209 |
-
|
| 210 |
-
async def capture_screenshot(page, config, replace_values=None):
|
| 211 |
-
"""Capture a single screenshot based on configuration"""
|
| 212 |
-
url = config['url']
|
| 213 |
-
if replace_values:
|
| 214 |
-
for key, value in replace_values.items():
|
| 215 |
-
url = url.replace(f"{{{key}}}", value)
|
| 216 |
-
|
| 217 |
-
logger.info(f"Capturing: {config['description']} -> {config['output']}")
|
| 218 |
-
|
| 219 |
-
try:
|
| 220 |
-
# Navigate to URL
|
| 221 |
-
await page.goto(url, wait_until='networkidle')
|
| 222 |
-
|
| 223 |
-
# Execute actions
|
| 224 |
-
for action in config.get('actions', []):
|
| 225 |
-
if action['type'] == 'click':
|
| 226 |
-
await page.click(action['selector'])
|
| 227 |
-
await page.wait_for_timeout(500)
|
| 228 |
-
|
| 229 |
-
elif action['type'] == 'type':
|
| 230 |
-
await page.fill(action['selector'], action['text'])
|
| 231 |
-
|
| 232 |
-
elif action['type'] == 'wait':
|
| 233 |
-
await page.wait_for_timeout(action['time'])
|
| 234 |
-
|
| 235 |
-
elif action['type'] == 'scroll':
|
| 236 |
-
await page.evaluate(f"window.scrollBy(0, {action['y']})")
|
| 237 |
-
await page.wait_for_timeout(500)
|
| 238 |
-
|
| 239 |
-
# Wait for any animations
|
| 240 |
-
await page.wait_for_timeout(config.get('wait_time', 1000))
|
| 241 |
-
|
| 242 |
-
# Take screenshot
|
| 243 |
-
output_path = Path(config['output'])
|
| 244 |
-
output_path.parent.mkdir(parents=True, exist_ok=True)
|
| 245 |
-
|
| 246 |
-
screenshot_options = {
|
| 247 |
-
"path": str(output_path),
|
| 248 |
-
"full_page": config.get('full_page', False)
|
| 249 |
-
}
|
| 250 |
-
|
| 251 |
-
if config.get('selector'):
|
| 252 |
-
element = page.locator(config['selector'])
|
| 253 |
-
await element.screenshot(path=str(output_path))
|
| 254 |
-
else:
|
| 255 |
-
await page.screenshot(**screenshot_options)
|
| 256 |
-
|
| 257 |
-
logger.info(f"✅ Saved: {output_path}")
|
| 258 |
-
return True
|
| 259 |
-
|
| 260 |
-
except Exception as e:
|
| 261 |
-
logger.error(f"❌ Failed: {config['description']} - {str(e)}")
|
| 262 |
-
return False
|
| 263 |
-
|
| 264 |
-
async def capture_huggingface_screenshots(username=None, space_name=None):
|
| 265 |
-
"""Capture HuggingFace-specific screenshots"""
|
| 266 |
-
logger.info("Capturing HuggingFace screenshots...")
|
| 267 |
-
|
| 268 |
-
if not username or not space_name:
|
| 269 |
-
logger.warning("No username/space_name provided. Using placeholders.")
|
| 270 |
-
username = "your-username"
|
| 271 |
-
space_name = "your-space-name"
|
| 272 |
-
|
| 273 |
-
replace_values = {
|
| 274 |
-
"username": username,
|
| 275 |
-
"space_name": space_name
|
| 276 |
-
}
|
| 277 |
-
|
| 278 |
-
async with async_playwright() as p:
|
| 279 |
-
browser = await p.chromium.launch(headless=False)
|
| 280 |
-
context = await browser.new_context(
|
| 281 |
-
viewport={'width': 1280, 'height': 800},
|
| 282 |
-
device_scale_factor=2
|
| 283 |
-
)
|
| 284 |
-
page = await context.new_page()
|
| 285 |
-
|
| 286 |
-
for name, config in DOCS_SCREENSHOTS.items():
|
| 287 |
-
await capture_screenshot(page, config, replace_values)
|
| 288 |
-
await page.wait_for_timeout(1000)
|
| 289 |
-
|
| 290 |
-
await browser.close()
|
| 291 |
-
|
| 292 |
-
async def capture_local_app_screenshots():
|
| 293 |
-
"""Capture local app screenshots"""
|
| 294 |
-
logger.info("Capturing local app screenshots...")
|
| 295 |
-
logger.info("Make sure the app is running on http://localhost:7860")
|
| 296 |
-
|
| 297 |
-
async with async_playwright() as p:
|
| 298 |
-
browser = await p.chromium.launch(headless=False)
|
| 299 |
-
context = await browser.new_context(
|
| 300 |
-
viewport={'width': 1280, 'height': 800},
|
| 301 |
-
device_scale_factor=2
|
| 302 |
-
)
|
| 303 |
-
page = await context.new_page()
|
| 304 |
-
|
| 305 |
-
for name, config in LOCAL_APP_SCREENSHOTS.items():
|
| 306 |
-
await capture_screenshot(page, config)
|
| 307 |
-
await page.wait_for_timeout(1000)
|
| 308 |
-
|
| 309 |
-
await browser.close()
|
| 310 |
-
|
| 311 |
-
async def main():
|
| 312 |
-
"""Main entry point"""
|
| 313 |
-
import sys
|
| 314 |
-
|
| 315 |
-
if len(sys.argv) > 1:
|
| 316 |
-
if sys.argv[1] == "local":
|
| 317 |
-
await capture_local_app_screenshots()
|
| 318 |
-
elif sys.argv[1] == "huggingface":
|
| 319 |
-
username = sys.argv[2] if len(sys.argv) > 2 else None
|
| 320 |
-
space_name = sys.argv[3] if len(sys.argv) > 3 else None
|
| 321 |
-
await capture_huggingface_screenshots(username, space_name)
|
| 322 |
-
else:
|
| 323 |
-
logger.error("Usage: python capture_docs_screenshots.py [local|huggingface] [username] [space_name]")
|
| 324 |
-
else:
|
| 325 |
-
# Capture both sets
|
| 326 |
-
await capture_local_app_screenshots()
|
| 327 |
-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