Create app.py
Browse files
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 ุฅูู
|