Spaces:
				
			
			
	
			
			
		Runtime error
		
	
	
	
			
			
	
	
	
	
		
		
		Runtime error
		
	Update app.py
Browse files
    	
        app.py
    CHANGED
    
    | 
         @@ -1,4 +1,5 @@ 
     | 
|
| 1 | 
         
             
            import os
         
     | 
| 
         | 
|
| 2 | 
         
             
            import time
         
     | 
| 3 | 
         
             
            from pathlib import Path
         
     | 
| 4 | 
         
             
            from typing import List, Dict
         
     | 
| 
         @@ -7,6 +8,7 @@ import streamlit as st 
     | 
|
| 7 | 
         
             
            import pandas as pd
         
     | 
| 8 | 
         
             
            import json
         
     | 
| 9 | 
         
             
            import yaml
         
     | 
| 
         | 
|
| 10 | 
         
             
            from docling.document_converter import DocumentConverter, PdfFormatOption
         
     | 
| 11 | 
         
             
            from docling.datamodel.base_models import InputFormat
         
     | 
| 12 | 
         
             
            from docling.datamodel.document import ConversionStatus
         
     | 
| 
         @@ -244,6 +246,16 @@ def display_multimodal_result(file_path: Path): 
     | 
|
| 244 | 
         
             
                                    except Exception as e:
         
     | 
| 245 | 
         
             
                                        st.error(f"Erreur d'affichage CSV : {str(e)}")
         
     | 
| 246 | 
         | 
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 247 | 
         
             
            # Interface utilisateur
         
     | 
| 248 | 
         
             
            def main():
         
     | 
| 249 | 
         
             
                st.title("📊🦆 Docling Document Converter")
         
     | 
| 
         @@ -276,12 +288,18 @@ def main(): 
     | 
|
| 276 | 
         
             
                        results = process_files(uploaded_files, config)
         
     | 
| 277 | 
         
             
                        display_results(results)
         
     | 
| 278 | 
         
             
                        st.success("✅ Conversion terminée avec succès !")
         
     | 
| 279 | 
         
            -
                         
     | 
| 280 | 
         
            -
             
     | 
| 281 | 
         
            -
             
     | 
| 282 | 
         
            -
             
     | 
| 283 | 
         
            -
             
     | 
| 284 | 
         
            -
             
     | 
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 285 | 
         | 
| 286 | 
         
             
            if __name__ == "__main__":
         
     | 
| 287 | 
         
             
                main()
         
     | 
| 
         | 
|
| 1 | 
         
             
            import os
         
     | 
| 2 | 
         
            +
            import io
         
     | 
| 3 | 
         
             
            import time
         
     | 
| 4 | 
         
             
            from pathlib import Path
         
     | 
| 5 | 
         
             
            from typing import List, Dict
         
     | 
| 
         | 
|
| 8 | 
         
             
            import pandas as pd
         
     | 
| 9 | 
         
             
            import json
         
     | 
| 10 | 
         
             
            import yaml
         
     | 
| 11 | 
         
            +
            import zipfile
         
     | 
| 12 | 
         
             
            from docling.document_converter import DocumentConverter, PdfFormatOption
         
     | 
| 13 | 
         
             
            from docling.datamodel.base_models import InputFormat
         
     | 
| 14 | 
         
             
            from docling.datamodel.document import ConversionStatus
         
     | 
| 
         | 
|
| 246 | 
         
             
                                    except Exception as e:
         
     | 
| 247 | 
         
             
                                        st.error(f"Erreur d'affichage CSV : {str(e)}")
         
     | 
| 248 | 
         | 
| 249 | 
         
            +
            def create_zip_buffer(directory: Path) -> bytes:
         
     | 
| 250 | 
         
            +
                buffer = io.BytesIO()
         
     | 
| 251 | 
         
            +
                with zipfile.ZipFile(buffer, 'w', zipfile.ZIP_DEFLATED) as zipf:
         
     | 
| 252 | 
         
            +
                    for root, _, files in os.walk(directory):
         
     | 
| 253 | 
         
            +
                        for file in files:
         
     | 
| 254 | 
         
            +
                            file_path = Path(root) / file
         
     | 
| 255 | 
         
            +
                            zipf.write(file_path, arcname=file_path.relative_to(directory.parent))
         
     | 
| 256 | 
         
            +
                buffer.seek(0)
         
     | 
| 257 | 
         
            +
                return buffer.getvalue()
         
     | 
| 258 | 
         
            +
             
     | 
| 259 | 
         
             
            # Interface utilisateur
         
     | 
| 260 | 
         
             
            def main():
         
     | 
| 261 | 
         
             
                st.title("📊🦆 Docling Document Converter")
         
     | 
| 
         | 
|
| 288 | 
         
             
                        results = process_files(uploaded_files, config)
         
     | 
| 289 | 
         
             
                        display_results(results)
         
     | 
| 290 | 
         
             
                        st.success("✅ Conversion terminée avec succès !")
         
     | 
| 291 | 
         
            +
                        
         
     | 
| 292 | 
         
            +
                        # Création du buffer ZIP
         
     | 
| 293 | 
         
            +
                        try:
         
     | 
| 294 | 
         
            +
                            zip_buffer = create_zip_buffer(OUTPUT_DIR)
         
     | 
| 295 | 
         
            +
                            st.download_button(
         
     | 
| 296 | 
         
            +
                                label="📥 Télécharger tous les résultats",
         
     | 
| 297 | 
         
            +
                                data=zip_buffer,
         
     | 
| 298 | 
         
            +
                                file_name="conversion_results.zip",
         
     | 
| 299 | 
         
            +
                                mime="application/zip"
         
     | 
| 300 | 
         
            +
                            )
         
     | 
| 301 | 
         
            +
                        except Exception as e:
         
     | 
| 302 | 
         
            +
                            st.error(f"Erreur lors de la création du ZIP : {str(e)}")
         
     | 
| 303 | 
         | 
| 304 | 
         
             
            if __name__ == "__main__":
         
     | 
| 305 | 
         
             
                main()
         
     |