Spaces:
Running
Running
File size: 26,380 Bytes
f9689d2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>StyleScript - Code to PDF Generator</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
/* Custom styles that can't be done with Tailwind */
.code-display {
font-family: 'Courier New', monospace;
tab-size: 4;
}
.theme-dark {
background-color: #1e293b;
color: #f8fafc;
}
.theme-light {
background-color: #ffffff;
color: #1e293b;
}
.theme-solarized {
background-color: #fdf6e3;
color: #657b83;
}
.pdf-preview {
width: 100%;
height: 500px;
border: 1px solid #e2e8f0;
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}
/* Animation for loading */
@keyframes pulse {
0%, 100% {
opacity: 1;
}
50% {
opacity: 0.5;
}
}
.animate-pulse {
animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}
</style>
</head>
<body class="bg-gray-50 min-h-screen">
<!-- Navigation -->
<nav class="bg-indigo-600 text-white shadow-lg">
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div class="flex justify-between h-16 items-center">
<div class="flex items-center">
<div class="flex-shrink-0 flex items-center">
<i class="fas fa-code text-2xl mr-2"></i>
<span class="text-xl font-bold">StyleScript</span>
</div>
</div>
<div class="hidden md:block">
<div class="ml-10 flex items-baseline space-x-4">
<a href="#" class="px-3 py-2 rounded-md text-sm font-medium bg-indigo-700">Home</a>
<a href="#" class="px-3 py-2 rounded-md text-sm font-medium hover:bg-indigo-500">History</a>
<a href="#" class="px-3 py-2 rounded-md text-sm font-medium hover:bg-indigo-500">About</a>
</div>
</div>
<div class="md:hidden">
<button class="mobile-menu-button p-2 rounded-md hover:bg-indigo-500 focus:outline-none">
<i class="fas fa-bars"></i>
</button>
</div>
</div>
</div>
</nav>
<!-- Hero Section -->
<div class="bg-indigo-700 text-white">
<div class="max-w-7xl mx-auto py-12 px-4 sm:px-6 lg:px-8">
<div class="text-center">
<h1 class="text-4xl font-extrabold tracking-tight sm:text-5xl md:text-6xl">
<span class="block">Transform Your Code</span>
<span class="block text-indigo-200">Into Beautiful PDFs</span>
</h1>
<p class="mt-3 max-w-md mx-auto text-base text-indigo-100 sm:text-lg md:mt-5 md:text-xl md:max-w-3xl">
Upload your code or text, describe how you want it styled, and get a professional PDF instantly.
</p>
</div>
</div>
</div>
<!-- Main Content -->
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
<div class="grid grid-cols-1 lg:grid-cols-2 gap-8">
<!-- Input Section -->
<div class="bg-white rounded-lg shadow-md p-6">
<h2 class="text-2xl font-bold text-gray-800 mb-4">Create Your PDF</h2>
<!-- File Upload -->
<div class="mb-6">
<label class="block text-sm font-medium text-gray-700 mb-2">Upload Text/Code File</label>
<div class="mt-1 flex justify-center px-6 pt-5 pb-6 border-2 border-gray-300 border-dashed rounded-md">
<div class="space-y-1 text-center">
<div class="flex text-sm text-gray-600">
<label for="file-upload" class="relative cursor-pointer bg-white rounded-md font-medium text-indigo-600 hover:text-indigo-500 focus-within:outline-none">
<span>Upload a file</span>
<input id="file-upload" name="file-upload" type="file" class="sr-only" accept=".txt,.py,.js,.java,.c,.cpp,.html,.css">
</label>
<p class="pl-1">or drag and drop</p>
</div>
<p class="text-xs text-gray-500">TXT, PY, JS, JAVA, C, CPP, HTML, CSS up to 10MB</p>
</div>
</div>
</div>
<!-- Or Enter Text Directly -->
<div class="mb-6">
<label for="code-input" class="block text-sm font-medium text-gray-700 mb-2">Or enter your text/code directly</label>
<textarea id="code-input" rows="10" class="code-display shadow-sm focus:ring-indigo-500 focus:border-indigo-500 mt-1 block w-full sm:text-sm border border-gray-300 rounded-md p-3"></textarea>
</div>
<!-- Styling Prompt -->
<div class="mb-6">
<label for="styling-prompt" class="block text-sm font-medium text-gray-700 mb-2">How should we style your PDF?</label>
<div class="mt-1 relative rounded-md shadow-sm">
<textarea id="styling-prompt" rows="3" class="shadow-sm focus:ring-indigo-500 focus:border-indigo-500 block w-full sm:text-sm border border-gray-300 rounded-md p-3" placeholder="Example: 'Generate PDF with dark background, Courier font, title "My Python Result", and line numbers'"></textarea>
</div>
<p class="mt-2 text-sm text-gray-500">Describe your desired styling in natural language</p>
</div>
<!-- Quick Style Options -->
<div class="mb-6">
<label class="block text-sm font-medium text-gray-700 mb-2">Quick Style Options</label>
<div class="grid grid-cols-3 gap-2">
<button onclick="applyQuickStyle('dark')" class="theme-dark py-2 px-3 rounded text-sm font-medium">Dark Theme</button>
<button onclick="applyQuickStyle('light')" class="theme-light py-2 px-3 rounded text-sm font-medium border border-gray-300">Light Theme</button>
<button onclick="applyQuickStyle('solarized')" class="theme-solarized py-2 px-3 rounded text-sm font-medium border border-gray-300">Solarized</button>
</div>
</div>
<!-- Generate Button -->
<button onclick="generatePDF()" class="w-full bg-indigo-600 hover:bg-indigo-700 text-white font-bold py-3 px-4 rounded-md flex items-center justify-center">
<i class="fas fa-magic mr-2"></i> Generate PDF
</button>
</div>
<!-- Preview Section -->
<div class="bg-white rounded-lg shadow-md p-6">
<div class="flex justify-between items-center mb-4">
<h2 class="text-2xl font-bold text-gray-800">PDF Preview</h2>
<div id="download-section" class="hidden">
<button onclick="downloadPDF()" class="bg-green-600 hover:bg-green-700 text-white font-bold py-2 px-4 rounded-md flex items-center">
<i class="fas fa-download mr-2"></i> Download PDF
</button>
</div>
</div>
<!-- Preview Container -->
<div id="preview-container" class="pdf-preview rounded-md flex items-center justify-center bg-gray-100">
<div class="text-center p-6">
<i class="fas fa-file-pdf text-5xl text-gray-400 mb-4"></i>
<p class="text-gray-500">Your PDF preview will appear here</p>
</div>
</div>
<!-- Loading State -->
<div id="loading-state" class="hidden mt-4">
<div class="flex items-center justify-center space-x-2">
<div class="w-4 h-4 rounded-full bg-indigo-600 animate-pulse"></div>
<div class="w-4 h-4 rounded-full bg-indigo-600 animate-pulse delay-100"></div>
<div class="w-4 h-4 rounded-full bg-indigo-600 animate-pulse delay-200"></div>
</div>
<p class="text-center mt-2 text-gray-600">Generating your PDF...</p>
</div>
<!-- Customization Options (shown after generation) -->
<div id="customization-options" class="hidden mt-6">
<h3 class="text-lg font-medium text-gray-800 mb-3">Customize Further</h3>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<!-- Font Family -->
<div>
<label for="font-family" class="block text-sm font-medium text-gray-700 mb-1">Font Family</label>
<select id="font-family" class="mt-1 block w-full pl-3 pr-10 py-2 text-base border-gray-300 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm rounded-md">
<option value="Courier">Courier</option>
<option value="Arial">Arial</option>
<option value="Times New Roman">Times New Roman</option>
<option value="Helvetica">Helvetica</option>
</select>
</div>
<!-- Font Size -->
<div>
<label for="font-size" class="block text-sm font-medium text-gray-700 mb-1">Font Size</label>
<select id="font-size" class="mt-1 block w-full pl-3 pr-10 py-2 text-base border-gray-300 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm rounded-md">
<option value="10">10pt</option>
<option value="11">11pt</option>
<option value="12" selected>12pt</option>
<option value="14">14pt</option>
<option value="16">16pt</option>
</select>
</div>
<!-- Line Numbers -->
<div>
<label for="line-numbers" class="block text-sm font-medium text-gray-700 mb-1">Line Numbers</label>
<select id="line-numbers" class="mt-1 block w-full pl-3 pr-10 py-2 text-base border-gray-300 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm rounded-md">
<option value="true">Show</option>
<option value="false">Hide</option>
</select>
</div>
<!-- Page Size -->
<div>
<label for="page-size" class="block text-sm font-medium text-gray-700 mb-1">Page Size</label>
<select id="page-size" class="mt-1 block w-full pl-3 pr-10 py-2 text-base border-gray-300 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm rounded-md">
<option value="A4">A4</option>
<option value="Letter">Letter</option>
<option value="Legal">Legal</option>
</select>
</div>
</div>
<button onclick="updatePreview()" class="mt-4 bg-indigo-600 hover:bg-indigo-700 text-white font-bold py-2 px-4 rounded-md flex items-center">
<i class="fas fa-sync-alt mr-2"></i> Update Preview
</button>
</div>
</div>
</div>
</div>
<!-- Features Section -->
<div class="bg-gray-100 py-12">
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div class="lg:text-center">
<h2 class="text-base text-indigo-600 font-semibold tracking-wide uppercase">Features</h2>
<p class="mt-2 text-3xl leading-8 font-extrabold tracking-tight text-gray-900 sm:text-4xl">
Why Choose StyleScript
</p>
</div>
<div class="mt-10">
<div class="grid grid-cols-1 gap-10 sm:grid-cols-2 lg:grid-cols-3">
<div class="bg-white overflow-hidden shadow rounded-lg">
<div class="px-4 py-5 sm:p-6">
<div class="flex items-center">
<div class="flex-shrink-0 bg-indigo-500 rounded-md p-3">
<i class="fas fa-language text-white text-xl"></i>
</div>
<div class="ml-5 w-0 flex-1">
<h3 class="text-lg font-medium text-gray-900">Natural Language Processing</h3>
<p class="mt-1 text-sm text-gray-500">
Describe your desired styling in plain English and let our AI do the work.
</p>
</div>
</div>
</div>
</div>
<div class="bg-white overflow-hidden shadow rounded-lg">
<div class="px-4 py-5 sm:p-6">
<div class="flex items-center">
<div class="flex-shrink-0 bg-indigo-500 rounded-md p-3">
<i class="fas fa-file-code text-white text-xl"></i>
</div>
<div class="ml-5 w-0 flex-1">
<h3 class="text-lg font-medium text-gray-900">Code Highlighting</h3>
<p class="mt-1 text-sm text-gray-500">
Automatic syntax highlighting for multiple programming languages.
</p>
</div>
</div>
</div>
</div>
<div class="bg-white overflow-hidden shadow rounded-lg">
<div class="px-4 py-5 sm:p-6">
<div class="flex items-center">
<div class="flex-shrink-0 bg-indigo-500 rounded-md p-3">
<i class="fas fa-sliders-h text-white text-xl"></i>
</div>
<div class="ml-5 w-0 flex-1">
<h3 class="text-lg font-medium text-gray-900">Customization</h3>
<p class="mt-1 text-sm text-gray-500">
Fine-tune every aspect of your PDF after generation.
</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Footer -->
<footer class="bg-gray-800 text-white">
<div class="max-w-7xl mx-auto py-12 px-4 sm:px-6 lg:px-8">
<div class="grid grid-cols-1 md:grid-cols-3 gap-8">
<div>
<h3 class="text-lg font-semibold mb-4">StyleScript</h3>
<p class="text-gray-300 text-sm">
Transform your code and text into beautifully styled PDF documents with just a few clicks.
</p>
</div>
<div>
<h3 class="text-lg font-semibold mb-4">Quick Links</h3>
<ul class="space-y-2">
<li><a href="#" class="text-gray-300 hover:text-white text-sm">Home</a></li>
<li><a href="#" class="text-gray-300 hover:text-white text-sm">Documentation</a></li>
<li><a href="#" class="text-gray-300 hover:text-white text-sm">API</a></li>
</ul>
</div>
<div>
<h3 class="text-lg font-semibold mb-4">Connect</h3>
<div class="flex space-x-4">
<a href="#" class="text-gray-300 hover:text-white"><i class="fab fa-twitter"></i></a>
<a href="#" class="text-gray-300 hover:text-white"><i class="fab fa-github"></i></a>
<a href="#" class="text-gray-300 hover:text-white"><i class="fab fa-discord"></i></a>
</div>
</div>
</div>
<div class="mt-8 pt-8 border-t border-gray-700 text-sm text-gray-400 text-center">
© 2023 StyleScript. All rights reserved.
</div>
</div>
</footer>
<script>
// Global variables
let currentPDFData = null;
// Apply quick style presets
function applyQuickStyle(style) {
let promptText = '';
switch(style) {
case 'dark':
promptText = 'Generate PDF with dark background, Courier font, white text, and line numbers';
break;
case 'light':
promptText = 'Generate PDF with light background, Arial font, black text, and no line numbers';
break;
case 'solarized':
promptText = 'Generate PDF with solarized light background, Consolas font, and line numbers';
break;
}
document.getElementById('styling-prompt').value = promptText;
}
// Generate PDF based on user input
function generatePDF() {
const codeInput = document.getElementById('code-input').value;
const stylingPrompt = document.getElementById('styling-prompt').value;
if (!codeInput && !document.getElementById('file-upload').files[0]) {
alert('Please enter some text/code or upload a file first');
return;
}
if (!stylingPrompt) {
alert('Please describe how you want your PDF styled');
return;
}
// Show loading state
document.getElementById('loading-state').classList.remove('hidden');
document.getElementById('preview-container').innerHTML = '';
// Hide download button and customization options during generation
document.getElementById('download-section').classList.add('hidden');
document.getElementById('customization-options').classList.add('hidden');
// In a real app, this would be an API call to your Python backend
// For demo purposes, we'll simulate the API call with setTimeout
setTimeout(() => {
// Simulate API response
const mockResponse = {
success: true,
pdfData: "data:application/pdf;base64,...", // In real app, this would be the actual PDF data
settings: {
fontFamily: 'Courier',
fontSize: '12',
lineNumbers: true,
theme: 'dark',
title: 'My Generated PDF'
}
};
// Process the response
if (mockResponse.success) {
currentPDFData = mockResponse.pdfData;
// Show PDF preview (in real app, this would be the actual PDF)
document.getElementById('preview-container').innerHTML = `
<div class="w-full h-full flex items-center justify-center">
<div class="text-center">
<i class="fas fa-file-pdf text-6xl text-indigo-600 mb-4"></i>
<h3 class="text-xl font-bold mb-2">PDF Preview</h3>
<p class="text-gray-600">In a real application, the actual PDF would be displayed here</p>
<p class="mt-2 text-sm text-gray-500">Font: ${mockResponse.settings.fontFamily}, Size: ${mockResponse.settings.fontSize}pt</p>
<p class="text-sm text-gray-500">Theme: ${mockResponse.settings.theme}, Line Numbers: ${mockResponse.settings.lineNumbers ? 'Yes' : 'No'}</p>
</div>
</div>
`;
// Show download button and customization options
document.getElementById('download-section').classList.remove('hidden');
document.getElementById('customization-options').classList.remove('hidden');
// Set the customization options to match the generated PDF
document.getElementById('font-family').value = mockResponse.settings.fontFamily;
document.getElementById('font-size').value = mockResponse.settings.fontSize;
document.getElementById('line-numbers').value = mockResponse.settings.lineNumbers;
} else {
alert('Failed to generate PDF. Please try again.');
}
// Hide loading state
document.getElementById('loading-state').classList.add('hidden');
}, 2000);
}
// Download the generated PDF
function downloadPDF() {
if (!currentPDFData) {
alert('No PDF generated yet');
return;
}
// In a real app, this would use the actual PDF data
alert('In a real application, this would download the PDF file');
// For demo purposes, we'll create a dummy download
const link = document.createElement('a');
link.href = '#'; // In real app, this would be currentPDFData
link.download = 'styled_code.pdf';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
// Update the PDF preview with new customization settings
function updatePreview() {
const fontFamily = document.getElementById('font-family').value;
const fontSize = document.getElementById('font-size').value;
const lineNumbers = document.getElementById('line-numbers').value === 'true';
// Show loading state
document.getElementById('loading-state').classList.remove('hidden');
// In a real app, this would send the updated settings to the backend
// For demo, we'll just update the displayed info
setTimeout(() => {
document.getElementById('preview-container').innerHTML = `
<div class="w-full h-full flex items-center justify-center">
<div class="text-center">
<i class="fas fa-file-pdf text-6xl text-indigo-600 mb-4"></i>
<h3 class="text-xl font-bold mb-2">Updated PDF Preview</h3>
<p class="text-gray-600">Settings updated successfully</p>
<p class="mt-2 text-sm text-gray-500">Font: ${fontFamily}, Size: ${fontSize}pt</p>
<p class="text-sm text-gray-500">Line Numbers: ${lineNumbers ? 'Yes' : 'No'}</p>
</div>
</div>
`;
// Hide loading state
document.getElementById('loading-state').classList.add('hidden');
}, 1000);
}
// Handle file upload
document.getElementById('file-upload').addEventListener('change', function(e) {
const file = e.target.files[0];
if (!file) return;
const reader = new FileReader();
reader.onload = function(e) {
document.getElementById('code-input').value = e.target.result;
};
reader.readAsText(file);
});
</script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=mhzftech/stylescript" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html> |