Spaces:
Runtime error
Runtime error
import gradio as gr | |
import subprocess | |
import os | |
import uuid | |
import shutil | |
def convert_pdf_to_html(pdf_file): | |
job_id = str(uuid.uuid4()) | |
work_dir = f"/tmp/{job_id}" | |
os.makedirs(work_dir, exist_ok=True) | |
input_path = os.path.join(work_dir, "input.pdf") | |
output_path = os.path.join(work_dir, "input.html") | |
with open(input_path, "wb") as f: | |
f.write(pdf_file.read()) | |
try: | |
result = subprocess.run( | |
["pdf2htmlEX", "--dest-dir", work_dir, "--embed", "cfijo", input_path], | |
capture_output=True, | |
text=True | |
) | |
if result.returncode != 0: | |
return f"Error:\n{result.stderr}" | |
if not os.path.exists(output_path): | |
return "Conversion failed: output HTML not found." | |
return output_path | |
finally: | |
shutil.rmtree(work_dir, ignore_errors=True) | |
gr.Interface( | |
fn=convert_pdf_to_html, | |
inputs=gr.File(type="filepath", label="Upload PDF"), | |
outputs=gr.File(label="Download HTML"), | |
allow_flagging="never" | |
).launch() | |