fhueni's picture
feat: add initial docling pipeline and readme
bdb093b
raw
history blame
9.07 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Medication List App</title>
<script src="./index.js" type="module"></script>
<script src="https://cdn.tailwindcss.com"></script>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet"/>
</head>
<body class="bg-gray-100 text-gray-800 antialiased">
<div id="model-loader-overlay"
class="fixed inset-0 bg-black bg-opacity-60 flex flex-col items-center justify-center z-50">
<div class="loader-large ease-linear rounded-full h-24 w-24 mb-4"></div>
<h2 class="text-center text-white text-xl font-semibold">Loading Model...</h2>
<p class="text-center text-white text-md mt-2">This may take a moment. The model is being downloaded to your
browser.</p>
<progress id="model-progress" value="0" max="100" class="w-64 mt-4 bg-gray-200 rounded-full h-2"></progress>
<p id="progress-text" class="text-center text-white text-sm mt-2">0%</p>
</div>
<main class="container mx-auto p-4 md:p-8">
<header class="text-center mb-8">
<h1 class="text-4xl font-bold text-gray-900">Granite Docling WebGPU</h1>
<p class="text-lg text-gray-600 mt-2">Convert document images to HTML using 🤗 Transformers.js!</p>
</header>
<div class="grid grid-cols-1 lg:grid-cols-2 gap-8">
<!-- Left Panel: Image Input -->
<div class="bg-white p-6 rounded-lg shadow-md">
<h2 class="text-2xl font-semibold mb-4">1. Select an Image</h2>
<div
id="image-drop-area"
class="border-2 border-dashed border-gray-300 rounded-lg p-8 text-center cursor-pointer transition-colors duration-200 hover:border-indigo-500 hover:bg-indigo-50"
>
<div id="image-placeholder">
<svg class="mx-auto h-12 w-12 text-gray-400" stroke="currentColor" fill="none" viewBox="0 0 48 48"
aria-hidden="true">
<path
d="M28 8H12a4 4 0 00-4 4v20m32-12v8m0 0v8a4 4 0 01-4 4H12a4 4 0 01-4-4v-4m32-4l-3.172-3.172a4 4 0 00-5.656 0L28 28M8 32l9.172-9.172a4 4 0 015.656 0L28 28m0 0l4 4m4-24h8m-4-4v8"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
/>
</svg>
<p class="mt-2 text-sm text-gray-600">
<span class="font-semibold text-indigo-600">Drag and drop</span>
or click to select a file
</p>
<p class="text-xs text-gray-500">PNG, JPG, WEBP</p>
<input type="file" id="file-input" class="hidden" accept="image/*"/>
</div>
<div id="image-preview-container" class="hidden relative">
<img id="image-preview" src="" alt="Selected image" class="mx-auto rounded-md shadow-sm"/>
<button
id="remove-image-btn"
class="absolute top-2 right-2 z-10 bg-red-500 text-white rounded-full p-2 hover:bg-red-600 transition-colors focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-red-500"
>
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
<path
fill-rule="evenodd"
d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z"
clip-rule="evenodd"
/>
</svg>
</button>
</div>
</div>
<div class="mt-4 flex">
<input
type="text"
id="prompt-input"
class="flex-1 px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm"
value="Convert this page to docling."
/>
<button
id="generate-btn"
class="ml-2 px-4 py-2 bg-indigo-600 text-white rounded-md hover:bg-indigo-700 disabled:bg-gray-400 disabled:cursor-not-allowed"
>
Generate
</button>
</div>
<h3 class="text-lg font-semibold mt-6 mb-3" id="examples-title">Or try an example:</h3>
<div class="flex space-x-4 overflow-x-auto" id="examples-container">
<img
src="./assets/document.png"
class="example-image h-36 w-auto border-2 border-gray-200 rounded-md cursor-pointer hover:border-indigo-500 transition-colors"
alt="Example document"
data-prompt="Convert this page to docling."
title="Document parsing"
/>
<img
src="./assets/chart.png"
class="example-image h-36 w-auto border-2 border-gray-200 rounded-md cursor-pointer hover:border-indigo-500 transition-colors"
alt="Example chart"
data-prompt="Convert chart to OTSL."
title="Chart parsing"
/>
<img
src="./assets/table.jpg"
class="example-image h-36 w-auto border-2 border-gray-200 rounded-md cursor-pointer hover:border-indigo-500 transition-colors"
alt="Example table"
data-prompt="Convert this table to OTSL."
title="Table parsing"
/>
<img
src="./assets/code.jpg"
class="example-image h-36 w-auto border-2 border-gray-200 rounded-md cursor-pointer hover:border-indigo-500 transition-colors"
alt="Example code"
data-prompt="Convert code to text."
title="Code parsing"
/>
</div>
</div>
<!-- Right Panel: Output -->
<div class="bg-white p-6 rounded-lg shadow-md flex flex-col">
<div class="flex justify-between items-center mb-4">
<h2 class="text-2xl font-semibold">2. View Result</h2>
<div id="processing-indicator" class="flex items-center space-x-2 text-gray-500 hidden">
<div class="loader-small ease-linear rounded-full h-6 w-6"></div>
<p class="text-sm">Processing image...</p>
</div>
<div class="flex items-center space-x-2">
<span class="text-sm font-medium">Docling</span>
<div class="relative inline-block w-10 mr-2 align-middle select-none transition duration-200 ease-in">
<input
type="checkbox"
name="toggle"
id="view-toggle"
class="toggle-checkbox absolute block w-6 h-6 rounded-full bg-white border-4 appearance-none cursor-pointer"
checked
/>
<label for="view-toggle"
class="toggle-label block overflow-hidden h-6 rounded-full bg-gray-300 cursor-pointer"></label>
</div>
<span class="text-sm font-medium text-indigo-600">HTML</span>
</div>
</div>
<div id="output-container" class="flex-1 border border-gray-200 rounded-lg overflow-hidden bg-gray-50">
<div id="welcome-message" class="h-full flex items-center justify-center text-center text-gray-500">
<p>Select an image to see the result here.</p>
</div>
<!-- Docling Output -->
<div id="docling-view" class="h-full p-4 hidden">
<pre class="h-full whitespace-pre-wrap text-sm overflow-auto"><code
id="docling-output"></code></pre>
</div>
<!-- HTML Output -->
<div id="html-view" class="h-full w-full">
<iframe id="html-iframe" sandbox="allow-scripts" class="w-full h-full border-0"></iframe>
</div>
</div>
</div>
</div>
</main>
<!-- Hidden canvas for image processing -->
<canvas id="hidden-canvas" class="hidden"></canvas>
</body>
</html>