Spaces:
Running
Running
Build a web application named "StyleScript" that allows users (especially students) to generate a PDF document from their code output or text files using a prompt. Core features: 1. A simple UI where user uploads a text file or enters output text manually. 2. User can enter a natural language prompt like: "Generate PDF of my output with dark background, Courier font, and title 'My Python Result'" 3. Parse the prompt to extract styling preferences (font, theme, title). 4. Generate a formatted PDF based on the prompt using Python (e.g., ReportLab, FPDF, pdfkit). 5. Provide a preview of the PDF and option to customize further (change font size, theme, alignment). 6. Allow download of the final PDF. 7. Bonus (optional): Save prompt history for logged-in users. Frontend Stack: HTML, CSS (Tailwind or Bootstrap), JavaScript Backend Stack: Python with Flask (or FastAPI) PDF Generator: Use libraries like ReportLab, WeasyPrint, or pdfkit Add comments and modular code structure so it's easy to expand in future. - Initial Deployment
f9689d2 verified Download index.html from mhzftech/stylescript: direct link, hf CLI and curl.
- Browser
- Download file 26.4 kB
-
https://huggingface.co/spaces/mhzftech/stylescript/resolve/main/index.html
- Command line
-
hf download hf://spaces/mhzftech/stylescript/index.html
-
curl -L -o index.html https://huggingface.co/spaces/mhzftech/stylescript/resolve/main/index.html
26.4 kB
| <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> |