Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -85,11 +85,43 @@ def process_image(image, use_llm, use_context):
|
|
| 85 |
except Exception as e:
|
| 86 |
return f"Error processing image: {str(e)}", "", "", None
|
| 87 |
|
|
|
|
| 88 |
def create_pdf(state, pdf_title, pdf_type):
|
| 89 |
"""Create a PDF file for download."""
|
| 90 |
if state is None or len(state) != 2:
|
| 91 |
return None
|
| 92 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
original_text, braille_text = state
|
| 94 |
comparison = (pdf_type == "Side-by-Side Comparison")
|
| 95 |
|
|
|
|
| 85 |
except Exception as e:
|
| 86 |
return f"Error processing image: {str(e)}", "", "", None
|
| 87 |
|
| 88 |
+
|
| 89 |
def create_pdf(state, pdf_title, pdf_type):
|
| 90 |
"""Create a PDF file for download."""
|
| 91 |
if state is None or len(state) != 2:
|
| 92 |
return None
|
| 93 |
|
| 94 |
+
original_text, braille_text = state
|
| 95 |
+
|
| 96 |
+
# Get ASCII representation for PDF
|
| 97 |
+
try:
|
| 98 |
+
braille_result = text_to_braille(original_text, use_context=False)
|
| 99 |
+
ascii_braille = braille_result.get('formatted_ascii', braille_text)
|
| 100 |
+
except:
|
| 101 |
+
ascii_braille = braille_text
|
| 102 |
+
|
| 103 |
+
comparison = (pdf_type == "Side-by-Side Comparison")
|
| 104 |
+
|
| 105 |
+
try:
|
| 106 |
+
pdf_buffer = generate_pdf(original_text, ascii_braille, pdf_title, comparison)
|
| 107 |
+
|
| 108 |
+
# Create a temporary file to save the PDF
|
| 109 |
+
temp_file_path = f"/tmp/{pdf_title.replace(' ', '_').lower()}.pdf"
|
| 110 |
+
|
| 111 |
+
# Write the buffer to a file
|
| 112 |
+
with open(temp_file_path, "wb") as f:
|
| 113 |
+
f.write(pdf_buffer.getvalue())
|
| 114 |
+
|
| 115 |
+
return temp_file_path
|
| 116 |
+
except Exception as e:
|
| 117 |
+
print(f"Error generating PDF: {str(e)}")
|
| 118 |
+
return None
|
| 119 |
+
|
| 120 |
+
def create_pdf2(state, pdf_title, pdf_type):
|
| 121 |
+
"""Create a PDF file for download."""
|
| 122 |
+
if state is None or len(state) != 2:
|
| 123 |
+
return None
|
| 124 |
+
|
| 125 |
original_text, braille_text = state
|
| 126 |
comparison = (pdf_type == "Side-by-Side Comparison")
|
| 127 |
|