/dev/null', $pathOut, $pathExitCode); if ($pathExitCode !== 0 || ! isset($pathOut[0]) || $pathOut[0] === '') { continue; } $candidatePath = $pathOut[0]; } $versionOut = []; $versionExitCode = 1; exec(escapeshellarg($candidatePath) . ' --version 2>/dev/null', $versionOut, $versionExitCode); if ($versionExitCode === 0) { $browserBinary = $candidatePath; break; } } if ($browserBinary === null) { return; } $command = sprintf( '%s --headless --disable-gpu --no-sandbox --disable-dev-shm-usage --hide-scrollbars --window-size=1440,900 --screenshot=%s --virtual-time-budget=8000 --run-all-compositor-stages-before-draw %s 2>/dev/null', escapeshellarg($browserBinary), escapeshellarg($previewPngPath), escapeshellarg($pageUrl) ); $output = []; $exitCode = 1; exec($command, $output, $exitCode); if ($exitCode !== 0 || ! file_exists($previewPngPath)) { @unlink($previewPngPath); return; } if (function_exists('imagecreatefrompng') && function_exists('imagejpeg')) { $image = @imagecreatefrompng($previewPngPath); if ($image !== false) { imagejpeg($image, $previewJpgPath, 85); imagedestroy($image); } } if (file_exists($previewJpgPath)) { @unlink($previewPngPath); } else { // Keep PNG as fallback if JPG conversion is unavailable. @rename($previewPngPath, $previewJpgPath); } } header('Content-Type: text/html; charset=UTF-8'); $startedAt = microtime(true); $apiKey = getenv('LLAMA_API_KEY') ?: ''; $model = getenv('LLAMA_MODEL') ?: 'local-model'; $maxTokens = (int) (getenv('LLAMA_MAX_TOKENS') ?: 4096); $reasoningEffort = getenv('LLAMA_REASONING_EFFORT') ?: 'none'; $topicHint = isset($_GET['topic']) ? trim((string) $_GET['topic']) : ''; $topicHint = mb_substr($topicHint, 0, 120); $seed = sprintf('seed-%08x%08x', random_int(0, 0xffffffff), random_int(0, 0xffffffff)); header('HX-Redirect: /' . $seed); $topicCategories = [ 'local restaurant landing page', 'fitness coaching brand site', 'travel destination mini-guide', 'event festival one-page promo', 'indie game launch page', 'architect portfolio page', 'music artist release page', 'bookstore seasonal campaign', 'pet adoption center homepage', 'artisan coffee roaster website', 'online course product page', 'nonprofit donation campaign page', ]; $selectedCategory = $topicCategories[array_rand($topicCategories)]; $bannedTerms = [ 'chrono', 'temporal', 'chrono-', 'timewarp', 'timescape', 'timeshift', 'quantum', 'aether', 'epoch', 'singularity', ]; $bannedTermsList = implode(', ', $bannedTerms); $factory = OpenAI::factory()->withBaseUri('http://localhost:8080/v1'); if ($apiKey !== '') { $factory = $factory->withApiKey($apiKey); } $client = $factory->make(); $systemPrompt = << and include full , , and . - Use Tailwind CSS via CDN in the same HTML document. - Do not rely on local/external project files. Everything required must be inside this single HTML file. - Inline any custom CSS and JavaScript in