Mohansai2004 commited on
Commit
c5322d4
·
verified ·
1 Parent(s): 447cc07

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, UploadFile, File
2
+ from fastapi.responses import JSONResponse
3
+ from PIL import Image
4
+ import io
5
+
6
+ app = FastAPI()
7
+
8
+ @app.get("/")
9
+ def read_root():
10
+ return {"message": "Space is running. Use POST /process-image"}
11
+
12
+ @app.post("/process-image")
13
+ async def process_image(file: UploadFile = File(...)):
14
+ try:
15
+ contents = await file.read()
16
+ image = Image.open(io.BytesIO(contents))
17
+ width, height = image.size
18
+
19
+ return JSONResponse(content={
20
+ "filename": file.filename,
21
+ "width": width,
22
+ "height": height,
23
+ "format": image.format
24
+ })
25
+ except Exception as e:
26
+ return JSONResponse(content={"error": str(e)}, status_code=400)