Commit
ยท
a7b1429
1
Parent(s):
bc53a36
app.py
CHANGED
|
@@ -1,9 +1,8 @@
|
|
| 1 |
from fastapi import FastAPI, HTTPException, Request
|
| 2 |
from fastapi.responses import FileResponse
|
| 3 |
import cv2
|
| 4 |
-
import numpy as np
|
| 5 |
from PIL import Image
|
| 6 |
-
import
|
| 7 |
import gdown
|
| 8 |
import os
|
| 9 |
import uuid
|
|
@@ -21,11 +20,40 @@ app = FastAPI(
|
|
| 21 |
],
|
| 22 |
)
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
@app.post("/detect-edges/")
|
| 25 |
def detect_edges(url: str, request: Request):
|
| 26 |
try:
|
| 27 |
# Google Drive ํ์ผ ID ์ถ์ถ
|
| 28 |
-
file_id = url
|
| 29 |
download_url = f"https://drive.google.com/uc?id={file_id}"
|
| 30 |
|
| 31 |
# ์ด๋ฏธ์ง๋ฅผ Google Drive์์ ๋ค์ด๋ก๋
|
|
|
|
| 1 |
from fastapi import FastAPI, HTTPException, Request
|
| 2 |
from fastapi.responses import FileResponse
|
| 3 |
import cv2
|
|
|
|
| 4 |
from PIL import Image
|
| 5 |
+
import re
|
| 6 |
import gdown
|
| 7 |
import os
|
| 8 |
import uuid
|
|
|
|
| 20 |
],
|
| 21 |
)
|
| 22 |
|
| 23 |
+
|
| 24 |
+
def extract_file_id(drive_url: str) -> str:
|
| 25 |
+
"""
|
| 26 |
+
Google Drive URL์์ ํ์ผ ID๋ฅผ ์ถ์ถํฉ๋๋ค.
|
| 27 |
+
|
| 28 |
+
Parameters:
|
| 29 |
+
drive_url (str): Google Drive ํ์ผ URL.
|
| 30 |
+
|
| 31 |
+
Returns:
|
| 32 |
+
str: ์ถ์ถ๋ ํ์ผ ID.
|
| 33 |
+
"""
|
| 34 |
+
# ์ ๊ท ํํ์์ ์ฌ์ฉํ์ฌ URL์์ ํ์ผ ID ์ถ์ถ
|
| 35 |
+
match = re.search(r'/d/([a-zA-Z0-9_-]+)', drive_url)
|
| 36 |
+
if match:
|
| 37 |
+
return match.group(1)
|
| 38 |
+
|
| 39 |
+
# ๋ค๋ฅธ URL ํ์์์ ํ์ผ ID ์ถ์ถ
|
| 40 |
+
match = re.search(r'file/d/([a-zA-Z0-9_-]+)', drive_url)
|
| 41 |
+
if match:
|
| 42 |
+
return match.group(1)
|
| 43 |
+
|
| 44 |
+
# ๊ณต์ ๋งํฌ์์ ํ์ผ ID ์ถ์ถ
|
| 45 |
+
match = re.search(r'([a-zA-Z0-9_-]{33,})', drive_url)
|
| 46 |
+
if match:
|
| 47 |
+
return match.group(1)
|
| 48 |
+
|
| 49 |
+
raise ValueError("Invalid Google Drive URL")
|
| 50 |
+
|
| 51 |
+
|
| 52 |
@app.post("/detect-edges/")
|
| 53 |
def detect_edges(url: str, request: Request):
|
| 54 |
try:
|
| 55 |
# Google Drive ํ์ผ ID ์ถ์ถ
|
| 56 |
+
file_id = extract_file_id(url)
|
| 57 |
download_url = f"https://drive.google.com/uc?id={file_id}"
|
| 58 |
|
| 59 |
# ์ด๋ฏธ์ง๋ฅผ Google Drive์์ ๋ค์ด๋ก๋
|