Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,29 @@
|
|
1 |
from fastapi import FastAPI
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
app = FastAPI()
|
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
@app.get("/")
|
6 |
-
def
|
7 |
-
|
8 |
-
return {"Hello": "World!"}
|
9 |
-
|
|
|
1 |
from fastapi import FastAPI
|
2 |
+
from pydantic import BaseModel
|
3 |
+
|
4 |
+
# Define a Pydantic model for the request body
|
5 |
+
class Item(BaseModel):
|
6 |
+
name: str
|
7 |
+
description: str = None
|
8 |
+
price: float
|
9 |
+
tax: float = None
|
10 |
|
11 |
app = FastAPI()
|
12 |
|
13 |
+
# Define a simple POST endpoint
|
14 |
+
@app.post("/items/")
|
15 |
+
async def create_item(item: Item):
|
16 |
+
# Perform some processing with the item data
|
17 |
+
total_price = item.price + (item.tax if item.tax else 0)
|
18 |
+
return {
|
19 |
+
"name": item.name,
|
20 |
+
"description": item.description,
|
21 |
+
"price": item.price,
|
22 |
+
"tax": item.tax,
|
23 |
+
"total_price": total_price,
|
24 |
+
}
|
25 |
+
|
26 |
+
# Define a simple GET endpoint
|
27 |
@app.get("/")
|
28 |
+
async def read_root():
|
29 |
+
return {"message": "Welcome to my FastAPI deployment on Hugging Face!"}
|
|
|
|