rapacious commited on
Commit
a61e482
·
verified ·
1 Parent(s): 8635cfd

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ !pip install gradio pdf2docx
2
+ import gradio as gr
3
+ from pdf2docx import Converter
4
+ import os
5
+ from pathlib import Path
6
+
7
+ # Hàm chuyển đổi PDF sang Word
8
+ def pdf_to_word(pdf_file):
9
+ try:
10
+ # Đường dẫn tạm thời cho file đầu ra
11
+ output_file = Path(pdf_file).stem + ".docx"
12
+
13
+ # Chuyển đổi PDF sang Word
14
+ cv = Converter(pdf_file)
15
+ cv.convert(output_file, start=0, end=None)
16
+ cv.close()
17
+
18
+ # Trả về file Word đã chuyển đổi
19
+ return output_file
20
+ except Exception as e:
21
+ return f"Lỗi: {str(e)}"
22
+
23
+ # Tạo giao diện Gradio
24
+ interface = gr.Interface(
25
+ fn=pdf_to_word, # Hàm xử lý
26
+ inputs=gr.File(label="Tải lên file PDF"), # Input: File PDF
27
+ outputs=gr.File(label="Tải xuống file Word"), # Output: File Word
28
+ title="Chuyển PDF sang Word",
29
+ description="Tải lên file PDF để chuyển đổi sang định dạng Word (.docx) giữ nguyên định dạng.",
30
+ theme="default"
31
+ )
32
+
33
+ # Chạy ứng dụng
34
+ interface.launch()