Skip to content

Commit

Permalink
Add support latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
freddyaboulton committed Jun 3, 2024
1 parent c17fb33 commit 67edd0c
Show file tree
Hide file tree
Showing 5 changed files with 778 additions and 372 deletions.
4 changes: 2 additions & 2 deletions frontend/Example.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
export let samples_dir: string;
export let type: "gallery" | "table";
export let selected = false;
import pdfjsLib from "pdfjs-dist";
pdfjsLib.GlobalWorkerOptions.workerSrc = "https://cdn.bootcss.com/pdf.js/3.11.174/pdf.worker.js";
import * as pdfjsLib from 'pdfjs-dist';
pdfjsLib.GlobalWorkerOptions.workerSrc = "https://cdn.jsdelivr.net/gh/freddyaboulton/gradio-pdf@main/pdf.worker.min.mjs";
let pdfDoc;
let canvasRef;
Expand Down
10 changes: 6 additions & 4 deletions frontend/Index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import { StatusTracker } from "@gradio/statustracker";
import type { LoadingStatus } from "@gradio/statustracker";
import type { FileData } from "@gradio/client";
import { normalise_file } from "@gradio/client";
import { Upload, ModifyUpload } from "@gradio/upload";
import * as pdfjsLib from 'pdfjs-dist';
Expand All @@ -30,16 +29,16 @@
upload: never;
}>;
pdfjsLib.GlobalWorkerOptions.workerSrc = "https://cdn.bootcss.com/pdf.js/3.11.174/pdf.worker.js";
pdfjsLib.GlobalWorkerOptions.workerSrc = "https://cdn.jsdelivr.net/gh/freddyaboulton/gradio-pdf@main/pdf.worker.min.mjs";
let _value = value;
let old_value = _value;
let pdfDoc;
let numPages = 1;
let canvasRef;
$: currentPage = Math.min(Math.max(starting_page, 1), numPages);
$: console.log("currentPage", currentPage);
async function handle_clear() {
_value = null;
Expand All @@ -65,7 +64,6 @@
function render_page(currentPage) {
// Render a specific page of the PDF onto the canvas
console.log("current Page here", currentPage);
pdfDoc.getPage(currentPage).then(page => {
const ctx = canvasRef.getContext('2d')
ctx.clearRect(0, 0, canvasRef.width, canvasRef.height);
Expand Down Expand Up @@ -100,6 +98,10 @@
}
$: height = height || 500;
function normalise_file(value, root, proxy_url) {
return value
}
// Compute the url to fetch the file from the backend\
// whenever a new value is passed in.
Expand Down
7 changes: 7 additions & 0 deletions frontend/gradio.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from "vite";

export default defineConfig({
build: {
target: 'esnext' //browsers can handle the latest ES features
}
})
Loading

0 comments on commit 67edd0c

Please sign in to comment.