Spaces:
				
			
			
	
			
			
		Sleeping
		
	
	
	
			
			
	
	
	
	
		
		
		Sleeping
		
	Update app.py
Browse files
    	
        app.py
    CHANGED
    
    | 
         @@ -182,8 +182,40 @@ def create_pdf_v2(state, pdf_title, pdf_type): 
     | 
|
| 182 | 
         
             
                    print(f"Error generating PDF: {str(e)}")
         
     | 
| 183 | 
         
             
                    return None
         
     | 
| 184 | 
         | 
| 185 | 
         
            -
             
     | 
| 186 | 
         
             
            def create_pdf(state, pdf_title, pdf_type):
         
     | 
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 187 | 
         
             
                """Create a PDF file for download."""
         
     | 
| 188 | 
         
             
                if state is None or len(state) != 2:
         
     | 
| 189 | 
         
             
                    return None
         
     | 
| 
         | 
|
| 182 | 
         
             
                    print(f"Error generating PDF: {str(e)}")
         
     | 
| 183 | 
         
             
                    return None
         
     | 
| 184 | 
         | 
| 
         | 
|
| 185 | 
         
             
            def create_pdf(state, pdf_title, pdf_type):
         
     | 
| 186 | 
         
            +
                """Create a PDF file for download."""
         
     | 
| 187 | 
         
            +
                if state is None:
         
     | 
| 188 | 
         
            +
                    return None
         
     | 
| 189 | 
         
            +
                
         
     | 
| 190 | 
         
            +
                # Extract data from state
         
     | 
| 191 | 
         
            +
                try:
         
     | 
| 192 | 
         
            +
                    original_text = state['original_text']
         
     | 
| 193 | 
         
            +
                    braille_text = state['braille_text']  # Use Unicode Braille text
         
     | 
| 194 | 
         
            +
                except:
         
     | 
| 195 | 
         
            +
                    # Fallback for backward compatibility
         
     | 
| 196 | 
         
            +
                    if isinstance(state, tuple) and len(state) == 2:
         
     | 
| 197 | 
         
            +
                        original_text, braille_text = state
         
     | 
| 198 | 
         
            +
                    else:
         
     | 
| 199 | 
         
            +
                        return None
         
     | 
| 200 | 
         
            +
                
         
     | 
| 201 | 
         
            +
                comparison = (pdf_type == "Side-by-Side Comparison")
         
     | 
| 202 | 
         
            +
                
         
     | 
| 203 | 
         
            +
                try:
         
     | 
| 204 | 
         
            +
                    pdf_buffer = generate_pdf(original_text, braille_text, pdf_title, comparison)
         
     | 
| 205 | 
         
            +
                    
         
     | 
| 206 | 
         
            +
                    # Create a temporary file to save the PDF
         
     | 
| 207 | 
         
            +
                    temp_file_path = f"/tmp/{pdf_title.replace(' ', '_').lower()}.pdf"
         
     | 
| 208 | 
         
            +
                    
         
     | 
| 209 | 
         
            +
                    # Write the buffer to a file
         
     | 
| 210 | 
         
            +
                    with open(temp_file_path, "wb") as f:
         
     | 
| 211 | 
         
            +
                        f.write(pdf_buffer.getvalue())
         
     | 
| 212 | 
         
            +
                    
         
     | 
| 213 | 
         
            +
                    return temp_file_path
         
     | 
| 214 | 
         
            +
                except Exception as e:
         
     | 
| 215 | 
         
            +
                    print(f"Error generating PDF: {str(e)}")
         
     | 
| 216 | 
         
            +
                    return None
         
     | 
| 217 | 
         
            +
             
     | 
| 218 | 
         
            +
            def create_pdf_v1_working(state, pdf_title, pdf_type):
         
     | 
| 219 | 
         
             
                """Create a PDF file for download."""
         
     | 
| 220 | 
         
             
                if state is None or len(state) != 2:
         
     | 
| 221 | 
         
             
                    return None
         
     |