Spaces:
Sleeping
Sleeping
Download webapp/services/io_utils.py from PeaceAbolisher/Model_Lab_Deployment: direct link, hf CLI and curl.
- Browser
- Download file 663 Bytes
-
https://huggingface.co/spaces/PeaceAbolisher/Model_Lab_Deployment/resolve/main/webapp/services/io_utils.py
- Command line
-
hf download hf://spaces/PeaceAbolisher/Model_Lab_Deployment/webapp/services/io_utils.py
-
curl -L -o io_utils.py https://huggingface.co/spaces/PeaceAbolisher/Model_Lab_Deployment/resolve/main/webapp/services/io_utils.py
663 Bytes
| # webapp/services/io_utils.py | |
| import io | |
| import pandas as pd | |
| def read_csv_or_txt(uploaded_file) -> pd.DataFrame: | |
| """Reads CSV or TXT. Ignores lines starting with #.""" | |
| if not uploaded_file: | |
| raise ValueError("Missing file.") | |
| raw = uploaded_file.read().decode("utf-8", errors="replace") | |
| lines = raw.splitlines() | |
| data_lines = [ln for ln in lines if not ln.strip().startswith("#")] | |
| if not data_lines: | |
| raise ValueError("No data rows found.") | |
| txt = "\n".join(data_lines) | |
| try: | |
| return pd.read_csv(io.StringIO(txt)) # comma | |
| except Exception: | |
| return pd.read_csv(io.StringIO(txt), sep="\t") # tab | |