Download src/reference_db/adapters/compliments.py from offCanada/reference-db-system: direct link, hf CLI and curl.
- Browser
- Download file 1.19 kB
-
https://huggingface.co/offCanada/reference-db-system/resolve/main/src/reference_db/adapters/compliments.py
- Command line
-
hf download hf://offCanada/reference-db-system/src/reference_db/adapters/compliments.py
-
curl -L -o compliments.py https://huggingface.co/offCanada/reference-db-system/resolve/main/src/reference_db/adapters/compliments.py
1.19 kB
| import duckdb | |
| from .base import RetailerAdapter | |
| PRODUCTS_SOURCE = ( | |
| "hf://datasets/saraNour/compliments-brand/" | |
| "raw_data/products.parquet" | |
| ) | |
| NUTRITION_SOURCE = ( | |
| "hf://datasets/saraNour/compliments-brand/" | |
| "raw_data/nutrition.parquet" | |
| ) | |
| class ComplimentsAdapter(RetailerAdapter): | |
| def retailer(self) -> str: | |
| return "sobeys" | |
| def _read_parquet(self, source: str): | |
| connection = duckdb.connect() | |
| connection.execute( | |
| "CREATE SECRET hf_token " | |
| "(TYPE huggingface, PROVIDER credential_chain)" | |
| ) | |
| reader = connection.sql( | |
| f"SELECT * FROM '{source}'" | |
| ).to_arrow_reader() | |
| return reader, connection | |
| def products(self): | |
| reader, connection = self._read_parquet(PRODUCTS_SOURCE) | |
| try: | |
| for batch in reader: | |
| yield from batch.to_pylist() | |
| finally: | |
| connection.close() | |
| def nutrition(self): | |
| reader, connection = self._read_parquet(NUTRITION_SOURCE) | |
| try: | |
| for batch in reader: | |
| yield from batch.to_pylist() | |
| finally: | |
| connection.close() |