| import gradio as gr |
| from pdf2docx import Converter |
| import os |
| from pathlib import Path |
|
|
| |
| def pdf_to_word(pdf_file): |
| try: |
| |
| output_file = Path(pdf_file).stem + ".docx" |
| |
| |
| cv = Converter(pdf_file) |
| cv.convert(output_file, start=0, end=None) |
| cv.close() |
| |
| |
| return output_file |
| except Exception as e: |
| return f"Lỗi: {str(e)}" |
|
|
| |
| interface = gr.Interface( |
| fn=pdf_to_word, |
| inputs=gr.File(label="Tải lên file PDF"), |
| outputs=gr.File(label="Tải xuống file Word"), |
| title="Chuyển PDF sang Word", |
| description="Tải lên file PDF để chuyển đổi sang định dạng Word (.docx) giữ nguyên định dạng.", |
| theme="default" |
| ) |
|
|
| |
| interface.launch() |