Spaces:
Configuration error
Configuration error
| from fastapi import FastAPI | |
| from pydantic import BaseModel | |
| from typing import List | |
| app = FastAPI( | |
| title="Brand Sort API", | |
| description="Sorts a list of brands alphabetically and removes duplicates.", | |
| version="1.0.0" | |
| ) | |
| class SortRequest(BaseModel): | |
| items: List[str] | |
| class SortResponse(BaseModel): | |
| sorted: List[str] | |
| def root(): | |
| return { | |
| "message": "Brand Sort API is running.", | |
| "endpoint": "/sort" | |
| } | |
| def sort_brands(request: SortRequest): | |
| # Remove duplicates while preserving first occurrence | |
| unique_items = list(dict.fromkeys(request.items)) | |
| # Sort alphabetically (case-insensitive) | |
| sorted_items = sorted(unique_items, key=str.lower) | |
| return {"sorted": sorted_items} | |
| def health(): | |
| return {"status": "ok"} |