Spaces:
Running
Running
Prathamesh Sable
commited on
Commit
·
15ab6a4
1
Parent(s):
2c89b88
update Analyze api
Browse files- main.py +13 -0
- routers/analysis.py +1 -1
main.py
CHANGED
|
@@ -24,6 +24,19 @@ app = FastAPI()
|
|
| 24 |
def read_root():
|
| 25 |
return RedirectResponse("/api")
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
@app.get("/api", response_class=HTMLResponse)
|
| 28 |
async def read_api(request: Request):
|
| 29 |
return templates.TemplateResponse("api_docs.html", {"request": request})
|
|
|
|
| 24 |
def read_root():
|
| 25 |
return RedirectResponse("/api")
|
| 26 |
|
| 27 |
+
# print every request data for request using middleware
|
| 28 |
+
@app.middleware("http")
|
| 29 |
+
async def log_requests(request: Request, call_next):
|
| 30 |
+
# Store the body content before sending to the next handler
|
| 31 |
+
body_content = await request.body()
|
| 32 |
+
# Create a new request with the consumed body
|
| 33 |
+
request._body = body_content
|
| 34 |
+
response = await call_next(request)
|
| 35 |
+
print(f"Request: {request.method} {request.url}")
|
| 36 |
+
print(f"Data: {body_content}")
|
| 37 |
+
print(f"Headers: {request.headers}")
|
| 38 |
+
return response
|
| 39 |
+
|
| 40 |
@app.get("/api", response_class=HTMLResponse)
|
| 41 |
async def read_api(request: Request):
|
| 42 |
return templates.TemplateResponse("api_docs.html", {"request": request})
|
routers/analysis.py
CHANGED
|
@@ -124,7 +124,7 @@ async def process_image(image: UploadFile = File(...)):
|
|
| 124 |
{
|
| 125 |
"message": "Product extracted successfully",
|
| 126 |
"product_image_name": extracted_product_name,
|
| 127 |
-
},status_code=200
|
| 128 |
)
|
| 129 |
else:
|
| 130 |
print("Failed to extract the product.")
|
|
|
|
| 124 |
{
|
| 125 |
"message": "Product extracted successfully",
|
| 126 |
"product_image_name": extracted_product_name,
|
| 127 |
+
}, status_code=200
|
| 128 |
)
|
| 129 |
else:
|
| 130 |
print("Failed to extract the product.")
|