Spaces:
Sleeping
Sleeping
| from pydantic import BaseModel, Field, field_validator | |
| from typing import List, Union | |
| # Pydantic Model for Response Validation | |
| class ContinentStats(BaseModel): | |
| continent: str = Field(..., title="Continent Name", example="Asia") | |
| Total_Countries: int = Field(..., title="Total Number of Countries", example=48) | |
| Total_Population: int = Field(..., title="Total Population", example=4600000000) | |
| Average_Population: float = Field(..., title="Average Population Per Country", example=96000000) | |
| Total_Area: int = Field(..., title="Total Land Area (sq km)", example=44679000) | |
| max_population: int = Field(..., title="Highest Country Population", example=1400000000) | |
| min_population: int = Field(..., title="Lowest Country Population", example=100000) | |
| Population_Density: float = Field(..., title="Population Density (people/sq km)", example=103) | |
| def must_be_positive(cls, value): | |
| if value < 0: | |
| raise ValueError("Value must be non-negative") | |
| return value | |