Spaces:
Runtime error
Runtime error
artificialguybr
commited on
Commit
•
cf73656
1
Parent(s):
8a91831
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,9 @@
|
|
1 |
import gradio as gr
|
2 |
from pdf2docx import Converter
|
3 |
-
from fpdf import FPDF
|
4 |
from docx import Document
|
|
|
5 |
import os
|
6 |
|
7 |
-
|
8 |
title_and_description = """
|
9 |
# PDF to Word and Word to PDF converter
|
10 |
Created by [@artificialguybr](https://artificialguy.com)
|
@@ -20,7 +19,6 @@ Upload a PDF file to convert to Word or a Word file to convert to PDF.
|
|
20 |
Feel free to use in your own documents!
|
21 |
"""
|
22 |
|
23 |
-
|
24 |
def pdf_to_word(pdf_file):
|
25 |
docx_filename = pdf_file.name.replace('.pdf', '.docx')
|
26 |
|
@@ -31,17 +29,17 @@ def pdf_to_word(pdf_file):
|
|
31 |
return docx_filename
|
32 |
|
33 |
def word_to_pdf(docx_file):
|
34 |
-
pdf_filename =
|
35 |
-
|
36 |
-
|
37 |
pdf = FPDF()
|
38 |
-
|
39 |
pdf.add_page()
|
40 |
-
pdf.set_font("
|
41 |
-
|
42 |
-
for
|
43 |
-
pdf.multi_cell(0, 10,
|
44 |
-
|
45 |
pdf.output(pdf_filename)
|
46 |
|
47 |
return pdf_filename
|
@@ -51,19 +49,19 @@ with gr.Blocks() as app:
|
|
51 |
|
52 |
with gr.Row():
|
53 |
with gr.Column():
|
54 |
-
with gr.Accordion("PDF
|
55 |
-
pdf_input = gr.File(label="
|
56 |
-
convert_pdf_to_word = gr.Button("
|
57 |
-
word_output = gr.File(label="
|
58 |
|
59 |
convert_pdf_to_word.click(pdf_to_word, inputs=[pdf_input], outputs=[word_output])
|
60 |
|
61 |
with gr.Column():
|
62 |
-
with gr.Accordion("Word
|
63 |
-
word_input = gr.File(label="
|
64 |
-
convert_word_to_pdf = gr.Button("
|
65 |
-
pdf_output = gr.File(label="
|
66 |
|
67 |
convert_word_to_pdf.click(word_to_pdf, inputs=[word_input], outputs=[pdf_output])
|
68 |
|
69 |
-
app.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from pdf2docx import Converter
|
|
|
3 |
from docx import Document
|
4 |
+
from fpdf import FPDF
|
5 |
import os
|
6 |
|
|
|
7 |
title_and_description = """
|
8 |
# PDF to Word and Word to PDF converter
|
9 |
Created by [@artificialguybr](https://artificialguy.com)
|
|
|
19 |
Feel free to use in your own documents!
|
20 |
"""
|
21 |
|
|
|
22 |
def pdf_to_word(pdf_file):
|
23 |
docx_filename = pdf_file.name.replace('.pdf', '.docx')
|
24 |
|
|
|
29 |
return docx_filename
|
30 |
|
31 |
def word_to_pdf(docx_file):
|
32 |
+
pdf_filename = docx_file.name.replace('.docx', '.pdf')
|
33 |
+
|
34 |
+
doc = Document(docx_file.name)
|
35 |
pdf = FPDF()
|
36 |
+
|
37 |
pdf.add_page()
|
38 |
+
pdf.set_font("Arial", size=12)
|
39 |
+
|
40 |
+
for para in doc.paragraphs:
|
41 |
+
pdf.multi_cell(0, 10, para.text)
|
42 |
+
|
43 |
pdf.output(pdf_filename)
|
44 |
|
45 |
return pdf_filename
|
|
|
49 |
|
50 |
with gr.Row():
|
51 |
with gr.Column():
|
52 |
+
with gr.Accordion("PDF to Word"):
|
53 |
+
pdf_input = gr.File(label="Upload PDF")
|
54 |
+
convert_pdf_to_word = gr.Button("Convert to Word")
|
55 |
+
word_output = gr.File(label="Download Word file", type="filepath")
|
56 |
|
57 |
convert_pdf_to_word.click(pdf_to_word, inputs=[pdf_input], outputs=[word_output])
|
58 |
|
59 |
with gr.Column():
|
60 |
+
with gr.Accordion("Word to PDF"):
|
61 |
+
word_input = gr.File(label="Upload Word")
|
62 |
+
convert_word_to_pdf = gr.Button("Convert to PDF")
|
63 |
+
pdf_output = gr.File(label="Download PDF file", type="filepath")
|
64 |
|
65 |
convert_word_to_pdf.click(word_to_pdf, inputs=[word_input], outputs=[pdf_output])
|
66 |
|
67 |
+
app.launch()
|