Download rag/app/utils/documents.py from Zamax14/api_rag: direct link, hf CLI and curl.
- Browser
- Download file 945 Bytes
-
https://huggingface.co/spaces/Zamax14/api_rag/resolve/main/rag/app/utils/documents.py
- Command line
-
hf download hf://spaces/Zamax14/api_rag/rag/app/utils/documents.py
-
curl -L -o documents.py https://huggingface.co/spaces/Zamax14/api_rag/resolve/main/rag/app/utils/documents.py
945 Bytes
| # ============================================================================== | |
| # Project Name: RAG LLM | |
| # Script Name: documents.py | |
| # Authors: Abraham Sánchez, Ulises Moya, Alejandro Zarate | |
| # Description: | |
| # This Python application provides an API service that retrieves answers to | |
| # user queries based on the given context. | |
| # | |
| # License: MIT | |
| # ============================================================================== | |
| import re | |
| from ..exceptions.app import InvalidFile | |
| from io import BytesIO | |
| from base64 import b64decode | |
| def extract(data_bytes: str, data_type: str) -> BytesIO | None: | |
| data = None | |
| if not data_type: | |
| return data_bytes | |
| rcomp = re.compile('application|pdf|text') | |
| if rcomp.findall(data_type): | |
| encoded = data_bytes.encode('utf-8') | |
| data_bytes = b64decode(encoded) | |
| bytesio = BytesIO(data_bytes) | |
| data = bytesio | |
| else: | |
| raise InvalidFile | |
| return data | |