Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,17 +1,17 @@
|
|
| 1 |
-
import
|
| 2 |
-
import
|
| 3 |
from PIL import Image
|
| 4 |
-
import numpy as np
|
| 5 |
import io
|
| 6 |
|
| 7 |
-
|
| 8 |
-
with mss.mss() as sct:
|
| 9 |
-
monitor = sct.monitors[1] # full screen
|
| 10 |
-
screenshot = sct.grab(monitor)
|
| 11 |
-
img = Image.frombytes("RGB", screenshot.size, screenshot.rgb)
|
| 12 |
-
return img
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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.post("/upload")
|
| 9 |
+
async def upload(file: UploadFile = File(...)):
|
| 10 |
+
try:
|
| 11 |
+
contents = await file.read()
|
| 12 |
+
image = Image.open(io.BytesIO(contents))
|
| 13 |
+
# You can run your AI analysis here
|
| 14 |
+
print("Screenshot received")
|
| 15 |
+
return JSONResponse({"status": "success"})
|
| 16 |
+
except Exception as e:
|
| 17 |
+
return JSONResponse({"status": "error", "details": str(e)})
|