Upload 2 files
Browse files- app.py +15 -6
- packages.txt +1 -2
app.py
CHANGED
|
@@ -52,11 +52,20 @@ def convert_docx_to_pdf(docx_path):
|
|
| 52 |
|
| 53 |
# Try LibreOffice conversion (works on Linux/HuggingFace)
|
| 54 |
if platform.system() != 'Windows':
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
else:
|
| 61 |
# For Windows, try using win32com with proper error handling
|
| 62 |
try:
|
|
@@ -492,7 +501,7 @@ with gr.Blocks(title="Certificate Generator & Email Sender", theme=gr.themes.Sof
|
|
| 492 |
)
|
| 493 |
|
| 494 |
send_email_checkbox = gr.Checkbox(
|
| 495 |
-
label="Send certificates via email
|
| 496 |
value=False
|
| 497 |
)
|
| 498 |
|
|
|
|
| 52 |
|
| 53 |
# Try LibreOffice conversion (works on Linux/HuggingFace)
|
| 54 |
if platform.system() != 'Windows':
|
| 55 |
+
try:
|
| 56 |
+
result = subprocess.run([
|
| 57 |
+
'libreoffice', '--headless', '--convert-to', 'pdf',
|
| 58 |
+
'--outdir', os.path.dirname(docx_path), docx_path
|
| 59 |
+
], check=True, capture_output=True, timeout=30)
|
| 60 |
+
|
| 61 |
+
if os.path.exists(output_pdf):
|
| 62 |
+
return output_pdf
|
| 63 |
+
else:
|
| 64 |
+
print(f"LibreOffice: PDF not created, using DOCX")
|
| 65 |
+
return docx_path
|
| 66 |
+
except (subprocess.CalledProcessError, FileNotFoundError, subprocess.TimeoutExpired) as e:
|
| 67 |
+
print(f"LibreOffice not available or failed: {e}. Using DOCX file.")
|
| 68 |
+
return docx_path
|
| 69 |
else:
|
| 70 |
# For Windows, try using win32com with proper error handling
|
| 71 |
try:
|
|
|
|
| 501 |
)
|
| 502 |
|
| 503 |
send_email_checkbox = gr.Checkbox(
|
| 504 |
+
label="Send certificates via email (PDF if available, otherwise DOCX)",
|
| 505 |
value=False
|
| 506 |
)
|
| 507 |
|
packages.txt
CHANGED
|
@@ -1,2 +1 @@
|
|
| 1 |
-
|
| 2 |
-
libreoffice-core
|
|
|
|
| 1 |
+
|
|
|