Commit
ยท
6cedaa8
1
Parent(s):
2d8a39b
- __pycache__/app.cpython-310.pyc +0 -0
- app.py +37 -18
- requirements.txt +2 -1
- tmp.ipynb +0 -0
__pycache__/app.cpython-310.pyc
ADDED
|
Binary file (1.11 kB). View file
|
|
|
app.py
CHANGED
|
@@ -1,8 +1,10 @@
|
|
| 1 |
-
from fastapi import FastAPI,
|
| 2 |
import cv2
|
| 3 |
import numpy as np
|
| 4 |
from fastapi.responses import StreamingResponse
|
| 5 |
import io
|
|
|
|
|
|
|
| 6 |
|
| 7 |
app = FastAPI(
|
| 8 |
version="0.0.1",
|
|
@@ -15,20 +17,37 @@ app = FastAPI(
|
|
| 15 |
)
|
| 16 |
|
| 17 |
@app.post("/detect-edges/")
|
| 18 |
-
|
| 19 |
-
#
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, HTTPException
|
| 2 |
import cv2
|
| 3 |
import numpy as np
|
| 4 |
from fastapi.responses import StreamingResponse
|
| 5 |
import io
|
| 6 |
+
import gdown
|
| 7 |
+
import os
|
| 8 |
|
| 9 |
app = FastAPI(
|
| 10 |
version="0.0.1",
|
|
|
|
| 17 |
)
|
| 18 |
|
| 19 |
@app.post("/detect-edges/")
|
| 20 |
+
def detect_edges(url: str):
|
| 21 |
+
# Google Drive ํ์ผ ID ์ถ์ถ
|
| 22 |
+
print('got ', str)
|
| 23 |
+
print('###############')
|
| 24 |
+
try:
|
| 25 |
+
file_id = url.split('/')[-2]
|
| 26 |
+
download_url = f"https://drive.google.com/uc?id={file_id}"
|
| 27 |
+
|
| 28 |
+
# ์ด๋ฏธ์ง๋ฅผ Google Drive์์ ๋ค์ด๋ก๋
|
| 29 |
+
output = 'temp_image.png'
|
| 30 |
+
gdown.download(download_url, output, quiet=False)
|
| 31 |
+
|
| 32 |
+
# ์ด๋ฏธ์ง๋ฅผ ์ฝ์ด๋ค์
|
| 33 |
+
img = cv2.imread(output)
|
| 34 |
+
|
| 35 |
+
# ์ด๋ฏธ์ง๊ฐ ์ ๋๋ก ์ฝํ๋์ง ํ์ธ
|
| 36 |
+
if img is None:
|
| 37 |
+
raise HTTPException(status_code=400, detail="Invalid image URL or file not found.")
|
| 38 |
+
|
| 39 |
+
# ์ฃ์ง ๋ํ
์
์ํ (Canny ์๊ณ ๋ฆฌ์ฆ ์ฌ์ฉ)
|
| 40 |
+
edges = cv2.Canny(img, 100, 200)
|
| 41 |
+
|
| 42 |
+
# ์ฃ์ง ์ด๋ฏธ์ง๋ฅผ ๋ค์ ์ธ์ฝ๋ฉ
|
| 43 |
+
_, buffer = cv2.imencode('.png', edges)
|
| 44 |
+
io_buf = io.BytesIO(buffer)
|
| 45 |
+
|
| 46 |
+
# ์์ ํ์ผ ์ญ์
|
| 47 |
+
os.remove(output)
|
| 48 |
+
|
| 49 |
+
# ๊ฒฐ๊ณผ ์ด๋ฏธ์ง๋ฅผ ์ฌ์ฉ์์๊ฒ ์ ์ก
|
| 50 |
+
return StreamingResponse(io_buf, media_type="image/png")
|
| 51 |
+
|
| 52 |
+
except Exception as e:
|
| 53 |
+
raise HTTPException(status_code=400, detail=str(e))
|
requirements.txt
CHANGED
|
@@ -5,4 +5,5 @@ opencv-python-headless # OpenCV, ์ด๋ฏธ์ง ์ฒ๋ฆฌ ๋ผ์ด๋ธ๋ฌ๋ฆฌ, GUI ๊ธฐ๋ฅ
|
|
| 5 |
Pillow # Python Imaging Library (PIL), ์ด๋ฏธ์ง ์์
์ ์ํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ
|
| 6 |
|
| 7 |
numpy # NumPy, OpenCV ๋ฐ ์ผ๋ฐ ์์น ๊ณ์ฐ์ ํ์
|
| 8 |
-
python-multipart
|
|
|
|
|
|
| 5 |
Pillow # Python Imaging Library (PIL), ์ด๋ฏธ์ง ์์
์ ์ํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ
|
| 6 |
|
| 7 |
numpy # NumPy, OpenCV ๋ฐ ์ผ๋ฐ ์์น ๊ณ์ฐ์ ํ์
|
| 8 |
+
python-multipart
|
| 9 |
+
gdown
|
tmp.ipynb
ADDED
|
File without changes
|