├── .gitignore ├── XPDF.jpg ├── README.md ├── docker-compose.yml ├── Dockerfile ├── tests └── tests ├── requirements.txt ├── global_common.py ├── splitting.py ├── data_extraction.postman_collection.json ├── extraction.py ├── .github └── workflows │ └── python-publish.yml ├── azure-pipelines.yml ├── app.py └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__ -------------------------------------------------------------------------------- /XPDF.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahmedkhemiri95/PDFs-TextExtract/HEAD/XPDF.jpg -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PDFs-TextExtract 2 | Multiple and Large PDF Documents Text Extraction. 3 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | # docker-compose.yaml 2 | version: '3' 3 | 4 | services: 5 | web: 6 | build: '.' 7 | ports: 8 | - '5000:5000' -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3.7 2 | COPY . /app/ 3 | WORKDIR /app 4 | RUN pip install -r requirements.txt 5 | ENTRYPOINT ["python3"] 6 | CMD ["app.py"] 7 | -------------------------------------------------------------------------------- /tests/tests: -------------------------------------------------------------------------------- 1 | curl -X POST http://127.0.0.1:5000/api/upload 2 | curl -X POST http://127.0.0.1:5000/api/upload --form 'files[]=@"toto.pdf"' --form 'files[]=@"toto2.pdf"' 3 | curl -X POST http://127.0.0.1:5000/api/extraction 4 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | click==8.0.1 2 | colorama==0.4.4 3 | Flask==2.0.1 4 | importlib-metadata==4.4.0 5 | itsdangerous==2.0.1 6 | Jinja2==3.0.1 7 | MarkupSafe==2.0.1 8 | pdfminer==20191125 9 | pycryptodome==3.10.1 10 | PyPDF2==1.26.0 11 | typing-extensions==3.10.0.0 12 | Werkzeug==2.0.1 13 | zipp==3.4.1 14 | numpy -------------------------------------------------------------------------------- /global_common.py: -------------------------------------------------------------------------------- 1 | import datetime 2 | import numpy as np 3 | import json 4 | 5 | 6 | def myconverter(o): 7 | 8 | if isinstance(o, datetime.datetime): 9 | return o.__str__() 10 | if isinstance(o, np.bool_): 11 | return o.__str__() 12 | 13 | 14 | def writeToJSONFile(filepath, data): 15 | with open(filepath, 'w') as file: 16 | json.dump(data, file, default=myconverter, indent=4) 17 | 18 | 19 | ports = { 20 | "data_extraction": 5000 21 | } 22 | 23 | PREFIX = "/api" 24 | -------------------------------------------------------------------------------- /splitting.py: -------------------------------------------------------------------------------- 1 | """ 2 | This script consist of: 3 | * Collect Pdf Files from uploads folder 4 | * Split Pdf Files page by page. 5 | * Save Splitted pdf pages to output Folder. 6 | """ 7 | 8 | import os 9 | from PyPDF2 import PdfFileReader, PdfFileWriter 10 | 11 | 12 | def splitting(upload_folder, split_folder): 13 | '''Do collect PDF files, split pages and save them 14 | ''' 15 | 16 | entries = os.listdir(upload_folder) 17 | path = os.path.abspath(split_folder) 18 | 19 | for entry in entries: 20 | 21 | uploaded_file = os.path.join(upload_folder, entry) 22 | output_file_folder = os.path.join(path, entry) 23 | 24 | if not os.path.isdir(output_file_folder): 25 | os.mkdir(output_file_folder) 26 | 27 | pdf = PdfFileReader(uploaded_file, strict=False) 28 | for page in range(pdf.getNumPages()): 29 | pdf_writer = PdfFileWriter() 30 | pdf_writer.addPage(pdf.getPage(page)) 31 | output_filename = \ 32 | os.path.join(output_file_folder, f'{page+1}.pdf') 33 | with open(output_filename, 'wb') as out: 34 | pdf_writer.write(out) 35 | -------------------------------------------------------------------------------- /data_extraction.postman_collection.json: -------------------------------------------------------------------------------- 1 | { 2 | "info": { 3 | "_postman_id": "e34a985e-d4fd-4dae-8b12-025041f50204", 4 | "name": "data_extraction", 5 | "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", 6 | "_exporter_id": "16050313" 7 | }, 8 | "item": [ 9 | { 10 | "name": "upload_data", 11 | "request": { 12 | "method": "POST", 13 | "header": [], 14 | "body": { 15 | "mode": "formdata", 16 | "formdata": [ 17 | { 18 | "key": "files[]", 19 | "type": "file", 20 | "src": [] 21 | } 22 | ] 23 | }, 24 | "url": { 25 | "raw": "http://127.0.0.1:5000/api/upload", 26 | "protocol": "http", 27 | "host": [ 28 | "127", 29 | "0", 30 | "0", 31 | "1" 32 | ], 33 | "port": "5000", 34 | "path": [ 35 | "api", 36 | "upload" 37 | ] 38 | } 39 | }, 40 | "response": [] 41 | }, 42 | { 43 | "name": "extract_text", 44 | "request": { 45 | "method": "POST", 46 | "header": [], 47 | "url": { 48 | "raw": "http://127.0.0.1:5000/api/extraction", 49 | "protocol": "http", 50 | "host": [ 51 | "127", 52 | "0", 53 | "0", 54 | "1" 55 | ], 56 | "port": "5000", 57 | "path": [ 58 | "api", 59 | "extraction" 60 | ] 61 | } 62 | }, 63 | "response": [] 64 | } 65 | ] 66 | } -------------------------------------------------------------------------------- /extraction.py: -------------------------------------------------------------------------------- 1 | """This module consists of: 2 | * Collect Splitted Pdf files. 3 | * Extract and save text files to output dir. 4 | """ 5 | 6 | import os 7 | from io import StringIO 8 | import re 9 | from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter 10 | from pdfminer.converter import TextConverter 11 | from pdfminer.layout import LAParams 12 | from pdfminer.pdfpage import PDFPage 13 | 14 | 15 | def pdf_to_text(path): 16 | '''Extract text from pdf documents 17 | ''' 18 | 19 | manager = PDFResourceManager() 20 | retstr = StringIO() 21 | layout = LAParams(all_texts=False, detect_vertical=True) 22 | device = TextConverter(manager, retstr, laparams=layout) 23 | interpreter = PDFPageInterpreter(manager, device) 24 | with open(path, 'rb') as filepath: 25 | for page in PDFPage.get_pages(filepath, check_extractable=True): 26 | interpreter.process_page(page) 27 | text = retstr.getvalue() 28 | device.close() 29 | retstr.close() 30 | return text 31 | 32 | 33 | def extraction(split_path, text_path): 34 | '''Extract and save text files to output dir 35 | ''' 36 | 37 | # entries names 38 | entries = os.listdir(split_path) 39 | 40 | # repeat the process for each entry 41 | for entry in entries: 42 | 43 | # define a custom list cotain entries files paths 44 | custom_list = os.listdir(os.path.join(split_path, entry)) 45 | 46 | # list must be sorted 47 | custom_list.sort(key=lambda f: int(re.sub(r'\D', '', f))) 48 | 49 | # repeat the process for each file path 50 | for file_path in custom_list: 51 | 52 | text_output = pdf_to_text( 53 | os.path.join(split_path, entry, file_path)) 54 | 55 | # save text file of each entry 56 | with open(os.path.join(text_path, f"{entry}.txt"), 57 | "a", 58 | encoding="utf-8") as text_file: 59 | text_file.write(text_output) 60 | -------------------------------------------------------------------------------- /.github/workflows/python-publish.yml: -------------------------------------------------------------------------------- 1 | # This workflow will upload a Python Package to PyPI when a release is created 2 | # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries 3 | 4 | # This workflow uses actions that are not certified by GitHub. 5 | # They are provided by a third-party and are governed by 6 | # separate terms of service, privacy policy, and support 7 | # documentation. 8 | 9 | name: Upload Python Package 10 | 11 | on: 12 | release: 13 | types: [published] 14 | 15 | permissions: 16 | contents: read 17 | 18 | jobs: 19 | release-build: 20 | runs-on: ubuntu-latest 21 | 22 | steps: 23 | - uses: actions/checkout@v4 24 | 25 | - uses: actions/setup-python@v5 26 | with: 27 | python-version: "3.x" 28 | 29 | - name: Build release distributions 30 | run: | 31 | # NOTE: put your own distribution build steps here. 32 | python -m pip install build 33 | python -m build 34 | 35 | - name: Upload distributions 36 | uses: actions/upload-artifact@v4 37 | with: 38 | name: release-dists 39 | path: dist/ 40 | 41 | pypi-publish: 42 | runs-on: ubuntu-latest 43 | needs: 44 | - release-build 45 | permissions: 46 | # IMPORTANT: this permission is mandatory for trusted publishing 47 | id-token: write 48 | 49 | # Dedicated environments with protections for publishing are strongly recommended. 50 | # For more information, see: https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment#deployment-protection-rules 51 | environment: 52 | name: pypi 53 | # OPTIONAL: uncomment and update to include your PyPI project URL in the deployment status: 54 | # url: https://pypi.org/p/YOURPROJECT 55 | # 56 | # ALTERNATIVE: if your GitHub Release name is the PyPI project version string 57 | # ALTERNATIVE: exactly, uncomment the following line instead: 58 | # url: https://pypi.org/project/YOURPROJECT/${{ github.event.release.name }} 59 | 60 | steps: 61 | - name: Retrieve release distributions 62 | uses: actions/download-artifact@v4 63 | with: 64 | name: release-dists 65 | path: dist/ 66 | 67 | - name: Publish release distributions to PyPI 68 | uses: pypa/gh-action-pypi-publish@release/v1 69 | with: 70 | packages-dir: dist/ 71 | -------------------------------------------------------------------------------- /azure-pipelines.yml: -------------------------------------------------------------------------------- 1 | # Python to Linux Web App on Azure 2 | # Build your Python project and deploy it to Azure as a Linux Web App. 3 | # Change python version to one thats appropriate for your application. 4 | # https://docs.microsoft.com/azure/devops/pipelines/languages/python 5 | 6 | trigger: 7 | - master 8 | 9 | variables: 10 | # Azure Resource Manager connection created during pipeline creation 11 | azureServiceConnectionId: '2b9a5a64-0432-4ea3-bc79-626f3676bed8' 12 | 13 | # Web app name 14 | webAppName: 'pdf_extraction' 15 | 16 | # Agent VM image name 17 | vmImageName: 'ubuntu-latest' 18 | 19 | # Environment name 20 | environmentName: '' 21 | 22 | # Project root folder. Point to the folder containing manage.py file. 23 | projectRoot: $(System.DefaultWorkingDirectory) 24 | 25 | # Python version: 3.7 26 | pythonVersion: '3.7' 27 | 28 | stages: 29 | - stage: Build 30 | displayName: Build stage 31 | jobs: 32 | - job: BuildJob 33 | pool: 34 | vmImage: $(vmImageName) 35 | steps: 36 | - task: UsePythonVersion@0 37 | inputs: 38 | versionSpec: '$(pythonVersion)' 39 | displayName: 'Use Python $(pythonVersion)' 40 | 41 | - script: | 42 | python -m venv antenv 43 | source antenv/bin/activate 44 | python -m pip install --upgrade pip 45 | pip install setup 46 | pip install -r requirements.txt 47 | workingDirectory: $(projectRoot) 48 | displayName: "Install requirements" 49 | 50 | - task: ArchiveFiles@2 51 | displayName: 'Archive files' 52 | inputs: 53 | rootFolderOrFile: '$(projectRoot)' 54 | includeRootFolder: false 55 | archiveType: zip 56 | archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip 57 | replaceExistingArchive: true 58 | 59 | - upload: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip 60 | displayName: 'Upload package' 61 | artifact: drop 62 | 63 | - stage: Deploy 64 | displayName: 'Deploy Web App' 65 | dependsOn: Build 66 | condition: succeeded() 67 | jobs: 68 | - deployment: DeploymentJob 69 | pool: 70 | vmImage: $(vmImageName) 71 | environment: $(environmentName) 72 | strategy: 73 | runOnce: 74 | deploy: 75 | steps: 76 | 77 | - task: UsePythonVersion@0 78 | inputs: 79 | versionSpec: '$(pythonVersion)' 80 | displayName: 'Use Python version' 81 | 82 | - task: AzureWebApp@1 83 | displayName: 'Deploy Azure Web App : ' 84 | inputs: 85 | azureSubscription: $(azureServiceConnectionId) 86 | appName: $(webAppName) 87 | package: $(Pipeline.Workspace)/drop/$(Build.BuildId).zip -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | '''Flask wrapping of the extraction related utilities 2 | ''' 3 | 4 | import os 5 | from flask import Flask, request, jsonify 6 | from werkzeug.utils import secure_filename 7 | 8 | from global_common import ports 9 | from global_common import PREFIX 10 | from extraction import extraction 11 | from splitting import splitting 12 | 13 | app = Flask(__name__) 14 | port = int(os.environ.get("PORT", ports["data_extraction"])) 15 | 16 | path = os.getcwd() 17 | 18 | # Project directories defined As follow: 19 | 20 | # -data_dir-: data . 21 | data = os.path.join(path, 'data') 22 | if not os.path.isdir(data): 23 | os.mkdir(data) 24 | 25 | # -upload_dir-: contain files uploaded. 26 | uploads = os.path.join(data, 'uploads') 27 | if not os.path.isdir(uploads): 28 | os.mkdir(uploads) 29 | 30 | # -preparation_dir-: contain processed & prepared files. 31 | prepare = os.path.join(data, 'files_preparation') 32 | if not os.path.isdir(prepare): 33 | os.mkdir(prepare) 34 | 35 | # -output_dir-: contain generated text files. 36 | outputs = os.path.join(data, 'outputs') 37 | if not os.path.isdir(outputs): 38 | os.mkdir(outputs) 39 | 40 | # Verify and validate files extensions... 41 | ALLOWED_EXTENSIONS = set(['.pdf']) 42 | 43 | 44 | def allowed_file(filename): 45 | '''Assess if the file extension is in the allowed listdir 46 | ''' 47 | lowercase_extension = os.path.splitext(filename)[1].lower() 48 | return lowercase_extension in ALLOWED_EXTENSIONS 49 | 50 | 51 | @app.route(PREFIX + '/upload', methods=['POST']) 52 | def upload(): 53 | '''Upload files to process 54 | ''' 55 | if request.method != 'POST': 56 | resp = jsonify({'message': 'Operation not supported'}) 57 | resp.status_code = 500 58 | return resp 59 | 60 | # check if the post request has the file part 61 | if 'files[]' not in request.files: 62 | resp = jsonify({'message': 'No file part in the request'}) 63 | resp.status_code = 500 64 | return resp 65 | 66 | files = request.files.getlist('files[]') 67 | 68 | errors = {} 69 | success = False 70 | 71 | # check if file allowed or not allowed. 72 | for file in files: 73 | if file and allowed_file(file.filename): 74 | filename = secure_filename(file.filename) 75 | file.save(os.path.join(uploads, filename)) 76 | success = True 77 | else: 78 | errors[file.filename] = 'File type is not allowed' 79 | 80 | if success and errors: 81 | errors['message'] = 'File(s) successfully uploaded' 82 | resp = jsonify(errors) 83 | resp.status_code = 404 84 | return resp 85 | 86 | if success: 87 | resp = jsonify({'message': 'Files successfully uploaded'}) 88 | resp.status_code = 200 89 | return resp 90 | 91 | resp = jsonify(errors) 92 | resp.status_code = 404 93 | return resp 94 | 95 | 96 | @app.route(PREFIX + '/extraction', methods=['POST']) 97 | def extract_function(): 98 | '''Do extract data from files 99 | ''' 100 | if request.method == 'POST': # check request method 101 | if not os.listdir(uploads): # if uploads dir is empty return -> error 102 | resp = jsonify({'message': 'Files not found'}) 103 | resp.status_code = 500 104 | return resp 105 | 106 | try: 107 | 108 | # splitting : split docs into single pages. 109 | splitting(uploads, prepare) 110 | 111 | # extraction: extract text from pages. 112 | extraction(prepare, outputs) 113 | 114 | resp = jsonify({'message': 'Files successfully extracted '}) 115 | resp.status_code = 200 116 | return resp 117 | 118 | except: 119 | 120 | resp = jsonify({'message': 'error occurs while extraction'}) 121 | resp.status_code = 404 122 | return resp 123 | else: 124 | 125 | resp = jsonify({'message': 'Operation not supported'}) 126 | resp.status_code = 500 127 | return resp 128 | 129 | 130 | if __name__ == '__main__': 131 | app.run(debug=True, host='0.0.0.0', port=port) 132 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------