Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -145,6 +145,45 @@ def process_image1(image, use_llm, use_context):
|
|
145 |
|
146 |
|
147 |
def create_pdf(state, pdf_title, pdf_type):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
"""Create a PDF file for download."""
|
149 |
if state is None or len(state) != 2:
|
150 |
return None
|
|
|
145 |
|
146 |
|
147 |
def create_pdf(state, pdf_title, pdf_type):
|
148 |
+
"""Create a PDF file for download."""
|
149 |
+
if state is None:
|
150 |
+
return None
|
151 |
+
|
152 |
+
# Extract data from state
|
153 |
+
try:
|
154 |
+
original_text = state['original_text']
|
155 |
+
ascii_braille = state['ascii_braille']
|
156 |
+
|
157 |
+
# If ASCII version is not available, use the Unicode version
|
158 |
+
if not ascii_braille:
|
159 |
+
ascii_braille = state['braille_text']
|
160 |
+
except:
|
161 |
+
# Fallback for backward compatibility
|
162 |
+
if isinstance(state, tuple) and len(state) == 2:
|
163 |
+
original_text, braille_text = state
|
164 |
+
ascii_braille = braille_text
|
165 |
+
else:
|
166 |
+
return None
|
167 |
+
|
168 |
+
comparison = (pdf_type == "Side-by-Side Comparison")
|
169 |
+
|
170 |
+
try:
|
171 |
+
pdf_buffer = generate_pdf(original_text, ascii_braille, pdf_title, comparison)
|
172 |
+
|
173 |
+
# Create a temporary file to save the PDF
|
174 |
+
temp_file_path = f"/tmp/{pdf_title.replace(' ', '_').lower()}.pdf"
|
175 |
+
|
176 |
+
# Write the buffer to a file
|
177 |
+
with open(temp_file_path, "wb") as f:
|
178 |
+
f.write(pdf_buffer.getvalue())
|
179 |
+
|
180 |
+
return temp_file_path
|
181 |
+
except Exception as e:
|
182 |
+
print(f"Error generating PDF: {str(e)}")
|
183 |
+
return None
|
184 |
+
|
185 |
+
|
186 |
+
def create_pdf11(state, pdf_title, pdf_type):
|
187 |
"""Create a PDF file for download."""
|
188 |
if state is None or len(state) != 2:
|
189 |
return None
|