Skip to content

Commit

Permalink
fix: dep
Browse files Browse the repository at this point in the history
  • Loading branch information
Byaidu committed Dec 13, 2024
1 parent 8e8cbe2 commit afe7c53
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 26 deletions.
34 changes: 8 additions & 26 deletions pdf2zh/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

import gradio as gr
from gradio_pdf import PDF
import numpy as np
import pymupdf
import tqdm
import requests
import cgi
Expand Down Expand Up @@ -79,19 +77,6 @@ def verify_recaptcha(response):
return result.get("success")


def pdf_preview(file):
doc = pymupdf.open(file)
page = doc[0]
pix = page.get_pixmap()
image = np.frombuffer(pix.samples, np.uint8).reshape(pix.height, pix.width, 3)
return image


def upload_file(file, service, progress=gr.Progress()):
preview_image = pdf_preview(file)
return file, file


def download_with_limit(url, save_path, size_limit):
chunk_size = 1024
total_size = 0
Expand Down Expand Up @@ -181,11 +166,6 @@ def progress_bar(t: tqdm.tqdm):
if not file_mono.exists() or not file_dual.exists():
raise gr.Error("No output")

try:
translated_preview = pdf_preview(str(file_mono))
except Exception:
raise gr.Error("No preview")

progress(1.0, desc="Translation complete!")

return (
Expand Down Expand Up @@ -335,7 +315,9 @@ def on_select_filetype(file_type):
)

output_title = gr.Markdown("## Translated", visible=False)
output_file = gr.File(label="Download Translation", visible=False)
output_file_mono = gr.File(
label="Download Translation (Mono)", visible=False
)
output_file_dual = gr.File(
label="Download Translation (Dual)", visible=False
)
Expand Down Expand Up @@ -385,9 +367,9 @@ def on_select_filetype(file_type):

# Event handlers
file_input.upload(
upload_file,
inputs=[file_input, service],
outputs=[file_input, preview],
lambda x: x,
inputs=file_input,
outputs=preview,
js=(
f"""
(a,b)=>{{
Expand Down Expand Up @@ -419,10 +401,10 @@ def on_select_filetype(file_type):
*envs,
],
outputs=[
output_file,
output_file_mono,
preview,
output_file_dual,
output_file,
output_file_mono,
output_file_dual,
output_title,
],
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ dependencies = [
"opencv-python-headless",
"tencentcloud-sdk-python",
"pdfminer.six>=20240706",
"gradio_pdf",
]

[project.optional-dependencies]
Expand Down

0 comments on commit afe7c53

Please sign in to comment.