Spaces:
Sleeping
Sleeping
diegokauer
commited on
Commit
•
2aaecad
1
Parent(s):
bced8ed
Update model.py
Browse files
model.py
CHANGED
@@ -9,6 +9,38 @@ from uuid import uuid4
|
|
9 |
from PIL import Image
|
10 |
|
11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
class Model(LabelStudioMLBase):
|
13 |
|
14 |
image_processor = AutoImageProcessor.from_pretrained("diegokauer/conditional-detr-coe-int")
|
@@ -23,7 +55,7 @@ class Model(LabelStudioMLBase):
|
|
23 |
|
24 |
|
25 |
image_path = task["data"]["image"]
|
26 |
-
image = Image.open(image_path)
|
27 |
original_width, original_height = image.size
|
28 |
with torch.no_grad():
|
29 |
|
|
|
9 |
from PIL import Image
|
10 |
|
11 |
|
12 |
+
import datetime
|
13 |
+
|
14 |
+
from google.cloud import storage
|
15 |
+
|
16 |
+
def generate_download_signed_url_v4(blob_name):
|
17 |
+
"""Generates a v4 signed URL for downloading a blob.
|
18 |
+
|
19 |
+
Note that this method requires a service account key file. You can not use
|
20 |
+
this if you are using Application Default Credentials from Google Compute
|
21 |
+
Engine or from the Google Cloud SDK.
|
22 |
+
"""
|
23 |
+
bucket_name = os.getenv("bucket")
|
24 |
+
|
25 |
+
storage_client = storage.Client()
|
26 |
+
bucket = storage_client.bucket(bucket_name)
|
27 |
+
blob = bucket.blob(blob_name)
|
28 |
+
|
29 |
+
url = blob.generate_signed_url(
|
30 |
+
version="v4",
|
31 |
+
# This URL is valid for 15 minutes
|
32 |
+
expiration=datetime.timedelta(minutes=15),
|
33 |
+
# Allow GET requests using this URL.
|
34 |
+
method="GET",
|
35 |
+
)
|
36 |
+
|
37 |
+
print("Generated GET signed URL:")
|
38 |
+
print(url)
|
39 |
+
print("You can use this URL with any user agent, for example:")
|
40 |
+
print(f"curl '{url}'")
|
41 |
+
return url
|
42 |
+
|
43 |
+
|
44 |
class Model(LabelStudioMLBase):
|
45 |
|
46 |
image_processor = AutoImageProcessor.from_pretrained("diegokauer/conditional-detr-coe-int")
|
|
|
55 |
|
56 |
|
57 |
image_path = task["data"]["image"]
|
58 |
+
image = Image.open(generate_download_signed_url_v4(image_path))
|
59 |
original_width, original_height = image.size
|
60 |
with torch.no_grad():
|
61 |
|