Spaces:
Sleeping
Sleeping
| from fastapi import FastAPI | |
| from pydantic import BaseModel | |
| # Define a Pydantic model for the request body | |
| class Item(BaseModel): | |
| name: str | |
| description: str = None | |
| price: float | |
| tax: float = None | |
| app = FastAPI() | |
| # Define a simple POST endpoint | |
| async def create_item(item: Item): | |
| # Perform some processing with the item data | |
| total_price = item.price + (item.tax if item.tax else 0) | |
| return { | |
| "name": item.name, | |
| "description": item.description, | |
| "price": item.price, | |
| "tax": item.tax, | |
| "total_price": total_price, | |
| } | |
| # Define a simple GET endpoint | |
| async def read_root(): | |
| return {"message": "Welcome to my FastAPI deployment on Hugging Face!"} | |