File size: 749 Bytes
53e7a1f
d364534
 
 
 
 
 
 
 
53e7a1f
 
 
d364534
 
 
 
 
 
 
 
 
 
 
 
 
 
53e7a1f
d364534
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
@app.post("/items/")
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
@app.get("/")
async def read_root():
    return {"message": "Welcome to my FastAPI deployment on Hugging Face!"}