-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutil.py
More file actions
46 lines (37 loc) · 1.13 KB
/
util.py
File metadata and controls
46 lines (37 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import boto3
from decouple import config
import json
import os
import requests
def create_tmp_path():
"""
Create temporary path for storing images
"""
img_dir = '/tmp/picasso'
if not os.path.exists(img_dir):
os.makedirs(img_dir)
def upload_to_s3(image):
"""
Connect to s3 instance and upload the transformed image.
Return the presigned url.
"""
s3_resource = boto3.resource('s3')
s3_bucket = s3_resource.Bucket(name='picasso-lambdaschool')
# Upload a file
upload_key = 'deeptransform/'+image
s3_bucket.upload_file(Filename=image, Key=upload_key)
# Get url
s3_client = boto3.client('s3')
url = s3_client.generate_presigned_url('get_object',
Params = {'Bucket': 'picasso-lambdaschool', 'Key': upload_key},
ExpiresIn = 100)
return url
def trigger_deeptransform_notification(key, output_url):
"""
This is the end point of deep neural style transformation
"""
url = config('NOTIFICATION_URL_PREFIX')+key
payload = {'output_url': output_url}
print(url)
print(payload)
r = requests.post(url, data=json.dumps(payload))