mrdilaw commited on
Commit
81ffa61
ยท
verified ยท
1 Parent(s): e1e4a32

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from pdf2docx import Converter
3
+ import os
4
+
5
+ def convert_pdf_to_word(pdf_file):
6
+ if pdf_file is None:
7
+ return "ูŠุฑุฌู‰ ุฑูุน ู…ู„ู PDF ุฃูˆู„ุงู‹."
8
+
9
+ # ุญูุธ ุงู„ู…ู„ู ุงู„ู…ุฑููˆุน
10
+ input_path = "input.pdf"
11
+ output_path = "output.docx"
12
+ with open(input_path, "wb") as f:
13
+ f.write(pdf_file.read())
14
+
15
+ # ุชุญูˆูŠู„ ุงู„ู…ู„ู
16
+ try:
17
+ cv = Converter(input_path)
18
+ cv.convert(output_path, start=0, end=None)
19
+ cv.close()
20
+ return output_path
21
+ except Exception as e:
22
+ return f"ุญุฏุซ ุฎุทุฃ ุฃุซู†ุงุก ุงู„ุชุญูˆูŠู„: {str(e)}"
23
+
24
+ # ูˆุงุฌู‡ุฉ Gradio
25
+ demo = gr.Interface(
26
+ fn=convert_pdf_to_word,
27
+ inputs=gr.File(label="ุงุฑูุน ู…ู„ู PDF ู‡ู†ุง"),
28
+ outputs=gr.File(label="ุชุญู…ูŠู„ ู…ู„ู Word ุงู„ู†ุงุชุฌ"),
29
+ title="ู…ุญูˆู„ PDF ุฅู„ู‰