Spaces:
Sleeping
Sleeping
Download acc_processor.py from utkarsh134/FastAPI-Img2CSV: direct link, hf CLI and curl.
- Browser
- Download file 4.96 kB
-
https://huggingface.co/spaces/utkarsh134/FastAPI-Img2CSV/resolve/4c1ad4bdb37796d87ebcc75ec843c2d8a097e649/acc_processor.py
- Command line
-
hf download hf://spaces/utkarsh134/FastAPI-Img2CSV@4c1ad4bdb37796d87ebcc75ec843c2d8a097e649/acc_processor.py
-
curl -L -o acc_processor.py https://huggingface.co/spaces/utkarsh134/FastAPI-Img2CSV/resolve/4c1ad4bdb37796d87ebcc75ec843c2d8a097e649/acc_processor.py
4.96 kB
| from enum import Enum | |
| from typing import Dict, Any | |
| class AccessoryType(Enum): | |
| PENDANT = "pendant" | |
| RINGBAND = "ringband" | |
| EARRING = "earring" | |
| BRACELET = "bracelet" | |
| NECKLACE = "necklace" | |
| class AccessoryProcessor: | |
| def __init__(self, accessory_type: str): | |
| # Convert string to enum | |
| try: | |
| self.accessory_type = AccessoryType(accessory_type.lower()) | |
| except ValueError: | |
| raise ValueError(f"Invalid accessory type. Must be one of: {[t.value for t in AccessoryType]}") | |
| def get_column_config(self) -> Dict[str, list]: | |
| base_columns = { | |
| "metal_columns": [ | |
| "Customer Ref", | |
| lambda x: next(col for col in x.keys() if "Gold Lock @" in col), | |
| lambda x: next(col for col in x.keys() if "Platinum Lock" in col), | |
| "Wt. in gram 14K", | |
| "Wt. in gram 18K", | |
| "Wt. in gram PLT", | |
| "Gold Value 14K", | |
| "Gold Value 18K", | |
| "Plat Value", | |
| "Gold Lock", | |
| "Platinum Lock" | |
| ], | |
| "price_columns": [ | |
| "Price of USD 14K", "Price of USD 18K", "Price of USD PT", | |
| "Price of GBP 14K @ 1/0.78", "Price of GBP 18K @ 1/0.78", "Price of GBP PT @ 1/0.78", | |
| "14K Duty @ 2.5% Including", "18K Duty @ 2.5% Including", "PT950 Duty @ 2.5% Including", | |
| "Freight", | |
| "14K Landing Cost (Duty + Freight)", "18K Landing Cost (Duty + Freight)", | |
| "PT950 Landing Cost (Duty + Freight)" | |
| ] | |
| } | |
| columns_config = { | |
| AccessoryType.PENDANT: { | |
| **base_columns, | |
| "finding_columns": [ | |
| "Finding For Gold 14KT", "Finding For Gold 18KT", "Finding for Plt.", | |
| "Rhodium", "Stamping" | |
| ], | |
| "labour_columns": ["Labour 14K", "Labour 18K", "Labour PT"] | |
| }, | |
| AccessoryType.RINGBAND: { | |
| **base_columns, | |
| "finding_columns": [ | |
| "CFP for Gold 14KT", "CFP for Gold 18KT", "CFP for Plt.", | |
| "Rhodium", "Stamping" | |
| ], | |
| "labour_columns": ["Labour 14K", "Labour 18K", "Labour PT"] | |
| }, | |
| AccessoryType.EARRING: { | |
| **base_columns, | |
| "finding_columns": [ | |
| "Finding & CFP For Gold 14KT", | |
| "Finding For Gold 18KT", | |
| "Finding for Plt.", | |
| "Rhodium", | |
| "Stamping" | |
| ], | |
| "labour_columns": ["Labour 14K", "Labour 18K", "Labour PT"] | |
| }, | |
| AccessoryType.BRACELET: { | |
| **base_columns, | |
| "finding_columns": [ | |
| "CFP For Gold 14KT", "CFP For Gold 18KT", "CFP For Gold PLT", | |
| "Rhodium", "Stamping", "Setting" | |
| ], | |
| "labour_columns": [] | |
| }, | |
| AccessoryType.NECKLACE: { | |
| **base_columns, | |
| "finding_columns": [ | |
| "CFP For Gold 14KT", "CFP For Gold 18KT", "CFP For Gold PLT", | |
| "Rhodium", "Stamping", "Setting" | |
| ], | |
| "labour_columns": [] | |
| } | |
| } | |
| return columns_config[self.accessory_type] | |
| def calculate_labour(self, metal_data: dict) -> dict: | |
| if self.accessory_type in [AccessoryType.BRACELET, AccessoryType.NECKLACE]: | |
| metal_data["Labour 14K"] = 0 | |
| metal_data["Labour 18K"] = 0 | |
| metal_data["Labour PT"] = 0 | |
| elif self.accessory_type == AccessoryType.RINGBAND: | |
| metal_data["Labour 14K"] = float(metal_data.get("Wt. in gram 14K", 0)) * 7 | |
| metal_data["Labour 18K"] = float(metal_data.get("Wt. in gram 18K", 0)) * 7 | |
| metal_data["Labour PT"] = float(metal_data.get("Wt. in gram PLT", 0)) * 11 | |
| elif self.accessory_type == AccessoryType.EARRING: | |
| metal_data["Labour 14K"] = 12 | |
| metal_data["Labour 18K"] = 12 | |
| metal_data["Labour PT"] = float(metal_data.get("Wt. in gram PLT", 0)) * 11 | |
| else: # Default PENDANT case | |
| metal_data["Labour 14K"] = round(12 if (float(metal_data.get("Wt. in gram 14K", 0)) * 7) < 12 | |
| else (float(metal_data.get("Wt. in gram 14K", 0)) * 7), 2) | |
| metal_data["Labour 18K"] = round(12 if (float(metal_data.get("Wt. in gram 18K", 0)) * 7) < 12 | |
| else (float(metal_data.get("Wt. in gram 18K", 0)) * 7), 2) | |
| metal_data["Labour PT"] = round(15 if (float(metal_data.get("Wt. in gram PLT", 0)) * 11) < 15 | |
| else (float(metal_data.get("Wt. in gram PLT", 0)) * 11), 2) | |
| return metal_data |