dahyedahye commited on
Commit
a7b1429
ยท
1 Parent(s): bc53a36
Files changed (1) hide show
  1. app.py +31 -3
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 io
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.split('/')[-2]
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์—์„œ ๋‹ค์šด๋กœ๋“œ