Spaces:
Build error
Build error
Download src/file_loader.py from amiguel/ai_systems: direct link, hf CLI and curl.
- Browser
- Download file 595 Bytes
-
https://huggingface.co/spaces/amiguel/ai_systems/resolve/main/src/file_loader.py
- Command line
-
hf download hf://spaces/amiguel/ai_systems/src/file_loader.py
-
curl -L -o file_loader.py https://huggingface.co/spaces/amiguel/ai_systems/resolve/main/src/file_loader.py
595 Bytes
| import pandas as pd | |
| import pdfplumber | |
| def load_file(uploaded_file): | |
| ext = uploaded_file.name.split(".")[-1].lower() | |
| if ext == "pdf": | |
| with pdfplumber.open(uploaded_file) as pdf: | |
| return [page.extract_text() for page in pdf.pages if page.extract_text()] | |
| elif ext == "csv": | |
| df = pd.read_csv(uploaded_file) | |
| return df.astype(str).apply(" ".join, axis=1).tolist() | |
| elif ext == "xlsx": | |
| df = pd.read_excel(uploaded_file) | |
| return df.astype(str).apply(" ".join, axis=1).tolist() | |
| else: | |
| raise ValueError("Unsupported file type") | |