Skip to content

Commit

Permalink
Debug commit
Browse files Browse the repository at this point in the history
  • Loading branch information
bhvishal9 committed Aug 20, 2024
1 parent 4f4d9c2 commit 570875f
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
4 changes: 1 addition & 3 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
PORT="8000"
AWS_ACCESS_KEY_ID="AWS_ACCESS_KEY_ID"
AWS_SECRET_ACCESS_KEY="AWS_SECRET_ACCESS_KEY"
S3_BUCKET="S3_BUCKET"
S3_TEST_BUCKET="S3_TEST_BUCKET"
S3_TEST_BUCKET="S3_TEST_BUCKET"
4 changes: 1 addition & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ x-build: &build
x-env: &env
environment:
- PORT=${PORT}
- AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
- AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
- S3_BUCKET=${S3_BUCKET}
- S3_TEST_BUCKET=${S3_TEST_BUCKET}
- SENTRY_DSN=${SENTRY_DSN}
Expand All @@ -19,4 +17,4 @@ services:
<<: [*build, *env]
command: gunicorn -w 4 'vectorizing:create_app()' --timeout 0 -b 0.0.0.0:$PORT --log-level debug
ports:
- ${PORT}:${PORT}
- ${PORT}:${PORT}
1 change: 1 addition & 0 deletions vectorizing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def index():
timer = Timer()

timer.start_timer('Image Reading')
print(url)
img = try_read_image_from_url(url)
timer.end_timer()

Expand Down
6 changes: 3 additions & 3 deletions vectorizing/server/s3.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import cuid
import boto3

S3 = boto3.client("s3")
S3 = boto3.client('s3')

def upload_markup (markup, s3_bucket_name):
cuid_str = cuid.cuid()
Expand All @@ -21,7 +21,7 @@ def get_object_url(s3_file_key, s3_bucket_name):
Key=s3_file_key,
Bucket=s3_bucket_name
)

except(Exception):
return None

Expand All @@ -40,4 +40,4 @@ def upload_file(
s3_bucket_name,
s3_file_key,
)
return get_object_url(s3_file_key, s3_bucket_name)
return get_object_url(s3_file_key, s3_bucket_name)
13 changes: 9 additions & 4 deletions vectorizing/util/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __init__(self):
def convert_RGB_A(img):
if img.mode == 'RGB' or img.mode == 'RGBA':
return img

map = {
'1': 'RGB',
'L': 'RGB',
Expand All @@ -33,7 +33,7 @@ def convert_RGB_A(img):

if not img.mode in map:
raise ImageFormatError()

return img.convert(map.get(img.mode))

def try_read_image_from_path(path):
Expand All @@ -46,7 +46,12 @@ def try_read_image_from_path(path):
def try_read_image_from_url(url):
try:
resp = requests.get(url, headers={"User-Agent": "KittlVectorizing/1.0.0"})
resp.raise_for_status() # Raise an HTTPError for bad responses (e.g., 403, 404)
img = Image.open(BytesIO(resp.content))
except:
except requests.exceptions.RequestException as e:
print(f"HTTP error occurred: {e}") # Detailed error message
raise URLReadError()
return convert_RGB_A(img)
except Exception as e:
print(f"Image processing error: {e}") # Detailed error message
raise URLReadError()
return convert_RGB_A(img)

0 comments on commit 570875f

Please sign in to comment.