Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -79,6 +79,30 @@ def create_pdf(state, pdf_title, pdf_type):
|
|
| 79 |
original_text, braille_text = state
|
| 80 |
comparison = (pdf_type == "Side-by-Side Comparison")
|
| 81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
pdf_buffer = generate_pdf(original_text, braille_text, pdf_title, comparison)
|
| 83 |
|
| 84 |
# Return the file for download
|
|
|
|
| 79 |
original_text, braille_text = state
|
| 80 |
comparison = (pdf_type == "Side-by-Side Comparison")
|
| 81 |
|
| 82 |
+
try:
|
| 83 |
+
pdf_buffer = generate_pdf(original_text, braille_text, pdf_title, comparison)
|
| 84 |
+
|
| 85 |
+
# Create a temporary file to save the PDF
|
| 86 |
+
temp_file_path = f"/tmp/{pdf_title.replace(' ', '_').lower()}.pdf"
|
| 87 |
+
|
| 88 |
+
# Write the buffer to a file
|
| 89 |
+
with open(temp_file_path, "wb") as f:
|
| 90 |
+
f.write(pdf_buffer.getvalue())
|
| 91 |
+
|
| 92 |
+
return temp_file_path
|
| 93 |
+
except Exception as e:
|
| 94 |
+
print(f"Error generating PDF: {str(e)}")
|
| 95 |
+
return None
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
def create_pdf1(state, pdf_title, pdf_type):
|
| 99 |
+
"""Create a PDF file for download."""
|
| 100 |
+
if state is None or len(state) != 2:
|
| 101 |
+
return None
|
| 102 |
+
|
| 103 |
+
original_text, braille_text = state
|
| 104 |
+
comparison = (pdf_type == "Side-by-Side Comparison")
|
| 105 |
+
|
| 106 |
pdf_buffer = generate_pdf(original_text, braille_text, pdf_title, comparison)
|
| 107 |
|
| 108 |
# Return the file for download
|