Spaces:
Runtime error
Runtime error
Commit
·
6d330c9
1
Parent(s):
f0f426c
Upload 6 files
Browse files- gradio_app.py +25 -0
- requirements.txt +0 -0
- utils/__pycache__/convert_helper.cpython-39.pyc +0 -0
- utils/__pycache__/helper.cpython-39.pyc +0 -0
- utils/convert_helper.py +9 -0
- utils/helper.py +12 -0
gradio_app.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from utils.convert_helper import convert_word_to_pdf
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
def gradio_word2pdf(word_path):
|
| 5 |
+
try:
|
| 6 |
+
input_path = word_path.name
|
| 7 |
+
output_path = r"D:\output.pdf"
|
| 8 |
+
|
| 9 |
+
result_message = convert_word_to_pdf(input_path,output_path)
|
| 10 |
+
return result_message
|
| 11 |
+
|
| 12 |
+
except Exception as e:
|
| 13 |
+
return f"An error occured:{e}"
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
interface = gr.Interface(fn=gradio_word2pdf,
|
| 17 |
+
inputs=gr.inputs.File(label="Input Word Document",type="file"),
|
| 18 |
+
outputs=gr.outputs.Textbox(label="Conversion Status"),
|
| 19 |
+
live=True,
|
| 20 |
+
title="Word To PDF Convertor",
|
| 21 |
+
description="Convert Word document to PDF files")
|
| 22 |
+
|
| 23 |
+
if __name__ == "__main__":
|
| 24 |
+
interface.launch()
|
| 25 |
+
|
requirements.txt
ADDED
|
Binary file (2.24 kB). View file
|
|
|
utils/__pycache__/convert_helper.cpython-39.pyc
ADDED
|
Binary file (498 Bytes). View file
|
|
|
utils/__pycache__/helper.cpython-39.pyc
ADDED
|
Binary file (675 Bytes). View file
|
|
|
utils/convert_helper.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from utils.helper import Word2Pdf
|
| 2 |
+
|
| 3 |
+
def convert_word_to_pdf(word_path,pdf_path):
|
| 4 |
+
try:
|
| 5 |
+
Word2Pdf.convert_word_to_pdf(word_path,pdf_path)
|
| 6 |
+
return f"Conversion Successfully. PDF saved at {pdf_path}"
|
| 7 |
+
except Exception as e:
|
| 8 |
+
return f"Error Occurred:{e}"
|
| 9 |
+
|
utils/helper.py
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from docx2pdf import convert
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
class Word2Pdf:
|
| 5 |
+
|
| 6 |
+
def convert_word_to_pdf(word_path,pdf_path):
|
| 7 |
+
try:
|
| 8 |
+
convert(word_path,pdf_path)
|
| 9 |
+
print(f"Conversion Successfully. PDF saved at {pdf_path}")
|
| 10 |
+
except Exception as e:
|
| 11 |
+
print(f"An error occured:{e}")
|
| 12 |
+
|