Spaces:
Runtime error
Runtime error
Download mapper/models.py from CleanflowAI/cleanflowai: direct link, hf CLI and curl.
- Browser
- Download file 3.58 kB
-
https://huggingface.co/spaces/CleanflowAI/cleanflowai/resolve/main/mapper/models.py
- Command line
-
hf download hf://spaces/CleanflowAI/cleanflowai/mapper/models.py
-
curl -L -o models.py https://huggingface.co/spaces/CleanflowAI/cleanflowai/resolve/main/mapper/models.py
3.58 kB
| """ | |
| Core data models and enums for the ERP to CDF transformation system. | |
| Provides type-safe definitions for entities, file formats, and transformation modes. | |
| """ | |
| from enum import Enum | |
| from typing import Dict, List, Optional, Union, Any | |
| from pathlib import Path | |
| from pydantic import BaseModel, Field | |
| import polars as pl | |
| class EntityType(str, Enum): | |
| """Supported entity types for ERP data transformation.""" | |
| SALES_ORDERS = "sales_orders" | |
| CUSTOMERS = "customers" | |
| INVOICES = "invoices" | |
| PURCHASE_ORDERS = "purchase_orders" | |
| INVENTORY_ITEMS = "inventory_items" | |
| class FileFormat(str, Enum): | |
| """Supported file formats for data processing.""" | |
| CSV = "csv" | |
| EXCEL = "excel" | |
| JSON = "json" | |
| SQL = "sql" | |
| class TransformationMode(str, Enum): | |
| """Transformation processing modes.""" | |
| TEMPLATE_BASED = "template" | |
| AI_ASSISTED = "ai" | |
| HYBRID = "hybrid" | |
| class TransformationRequest(BaseModel): | |
| """Request model for transformation operations.""" | |
| auto_select_erp: bool = Field(True, description="Auto-detect ERP system") | |
| auto_select_entity: bool = Field(True, description="Auto-detect entity type") | |
| entity: Optional[str] = Field(None, description="Entity type (ignored if auto_select_entity=True)") | |
| erp: Optional[str] = Field(None, description="ERP system (ignored if auto_select_erp=True)") | |
| file_data: Optional[Union[str, Path, bytes]] = Field(None, description="File path, bytes, or data") | |
| file_format: Optional[FileFormat] = Field(None, description="File format (auto-detected if None)") | |
| class TransformationResult(BaseModel): | |
| """Result of transformation operation.""" | |
| success: bool = Field(description="Whether transformation was successful") | |
| data: Optional[Any] = Field(None, description="Transformed DataFrame (as dict for JSON serialization)") | |
| detected_erp: Optional[str] = Field(None, description="Auto-detected ERP system") | |
| detected_entity: Optional[str] = Field(None, description="Auto-detected entity type") | |
| transformation_mode: Optional[TransformationMode] = Field(None, description="Mode used for transformation") | |
| confidence_score: Optional[float] = Field(None, description="Confidence in detection/mapping (0.0-1.0)") | |
| message: Optional[str] = Field(None, description="Additional information or error message") | |
| column_mappings: Optional[Dict[str, str]] = Field(None, description="Applied column mappings") | |
| class Config: | |
| """Pydantic configuration.""" | |
| arbitrary_types_allowed = True | |
| class AnalysisResult(BaseModel): | |
| """Result of data analysis operation.""" | |
| column_info: Dict[str, Any] = Field(description="Column information and statistics") | |
| erp_entity_suggestions: List[Dict[str, Any]] = Field(description="Suggested ERP/entity combinations") | |
| available_entities: List[str] = Field(description="Available entity types") | |
| available_erps: List[str] = Field(description="Available ERP systems") | |
| processing_time_ms: Optional[float] = Field(None, description="Processing time in milliseconds") | |
| class MappingConfidence(BaseModel): | |
| """Confidence scoring for mappings.""" | |
| erp: str = Field(description="ERP system name") | |
| entity: str = Field(description="Entity type") | |
| confidence: float = Field(description="Confidence score (0.0-1.0)") | |
| above_threshold: bool = Field(description="Whether confidence is above minimum threshold") | |
| matched_columns: int = Field(description="Number of matched columns") | |
| total_columns: int = Field(description="Total number of columns in template") | |