Spaces:
Sleeping
Sleeping
Ari
commited on
Commit
•
cffceba
1
Parent(s):
eaae758
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,13 @@ import gradio as gr
|
|
2 |
from docx import Document # For .docx handling
|
3 |
from gtts import gTTS
|
4 |
import os
|
5 |
-
import pdfkit
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
# Function to extract text from a .docx file and convert to PDF
|
8 |
def docx_to_pdf(docx_file):
|
@@ -22,9 +28,9 @@ def docx_to_pdf(docx_file):
|
|
22 |
</html>
|
23 |
"""
|
24 |
|
25 |
-
# Generate the PDF using pdfkit
|
26 |
pdf_output_path = "document_output.pdf"
|
27 |
-
pdfkit.from_string(html_content, pdf_output_path)
|
28 |
|
29 |
# Convert the text to audio using gTTS
|
30 |
tts = gTTS(text=extracted_text, lang='en', slow=False)
|
|
|
2 |
from docx import Document # For .docx handling
|
3 |
from gtts import gTTS
|
4 |
import os
|
5 |
+
import pdfkit
|
6 |
+
|
7 |
+
# Path to the wkhtmltopdf executable (update this path based on the Dockerfile output)
|
8 |
+
WKHTMLTOPDF_PATH = "/usr/local/bin/wkhtmltopdf" # You will get this from the Dockerfile output
|
9 |
+
|
10 |
+
# Configure pdfkit to use the correct wkhtmltopdf path
|
11 |
+
config = pdfkit.configuration(wkhtmltopdf=WKHTMLTOPDF_PATH)
|
12 |
|
13 |
# Function to extract text from a .docx file and convert to PDF
|
14 |
def docx_to_pdf(docx_file):
|
|
|
28 |
</html>
|
29 |
"""
|
30 |
|
31 |
+
# Generate the PDF using pdfkit with the custom wkhtmltopdf path
|
32 |
pdf_output_path = "document_output.pdf"
|
33 |
+
pdfkit.from_string(html_content, pdf_output_path, configuration=config)
|
34 |
|
35 |
# Convert the text to audio using gTTS
|
36 |
tts = gTTS(text=extracted_text, lang='en', slow=False)
|