Carsten Høyer
commited on
Commit
·
a168b4f
1
Parent(s):
dc5bc59
receive
Browse files
app.py
CHANGED
|
@@ -1,7 +1,34 @@
|
|
| 1 |
from fastapi import FastAPI
|
|
|
|
|
|
|
| 2 |
|
|
|
|
| 3 |
app = FastAPI()
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
@app.get("/")
|
| 6 |
def greet_json():
|
| 7 |
return {"Hello": "World!"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
from typing import List
|
| 4 |
|
| 5 |
+
# Initialize the FastAPI app
|
| 6 |
app = FastAPI()
|
| 7 |
|
| 8 |
+
# Define a Pydantic model for the items
|
| 9 |
+
class Item(BaseModel):
|
| 10 |
+
text: str
|
| 11 |
+
name: str
|
| 12 |
+
section: str
|
| 13 |
+
|
| 14 |
+
# A simple GET endpoint
|
| 15 |
@app.get("/")
|
| 16 |
def greet_json():
|
| 17 |
return {"Hello": "World!"}
|
| 18 |
+
|
| 19 |
+
# A POST endpoint to receive and parse an array of JSON objects
|
| 20 |
+
@app.post("/")
|
| 21 |
+
def create_items(items: List[Item]):
|
| 22 |
+
# Process each item in the list
|
| 23 |
+
processed_items = []
|
| 24 |
+
for item in items:
|
| 25 |
+
# Here you could perform any processing you need on each item
|
| 26 |
+
processed_item = {
|
| 27 |
+
"text": item.text,
|
| 28 |
+
"name": item.name,
|
| 29 |
+
"section": item.section,
|
| 30 |
+
"processed": True # Example of adding a field to indicate processing
|
| 31 |
+
}
|
| 32 |
+
processed_items.append(processed_item)
|
| 33 |
+
|
| 34 |
+
return {"processed_items": processed_items}
|