Skip to content
This repository was archived by the owner on May 8, 2025. It is now read-only.

Commit 66f4199

Browse files
committed
feat: defaults to base64
1 parent 082f638 commit 66f4199

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

builder/requirements.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# Required Python packages get listed here, one per line.
22
# Reccomended to lock the version number to avoid unexpected changes.
33

4-
runpod==1.0.0
5-
# git+https://github.com/runpod/runpod-python
4+
runpod==1.2.0
65

76
diffusers==0.12.1
87
torch==1.13.1 --extra-index-url=https://download.pytorch.org/whl/cu116

src/rp_handler.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
''' infer.py for runpod worker '''
22

33
import os
4+
import base64
45
import predict
56
import argparse
67

@@ -12,6 +13,18 @@
1213
from rp_schema import INPUT_SCHEMA
1314

1415

16+
def upload_or_base64_encode(file_name, img_path):
17+
"""
18+
Uploads image to S3 bucket if it is available, otherwise returns base64 encoded image.
19+
"""
20+
if os.environ.get('BUCKET_ENDPOINT_URL', False):
21+
return upload_file_to_bucket(file_name, img_path)
22+
23+
with open(img_path, "rb") as image_file:
24+
encoded_string = base64.b64encode(image_file.read())
25+
return encoded_string.decode("utf-8")
26+
27+
1528
def run(job):
1629
'''
1730
Run inference on the model.
@@ -58,10 +71,10 @@ def run(job):
5871
job_output = []
5972
for index, img_path in enumerate(img_paths):
6073
file_name = f"{job['id']}_{index}.png"
61-
image_url = upload_file_to_bucket(file_name, img_path)
74+
image_return = upload_or_base64_encode(file_name, img_path)
6275

6376
job_output.append({
64-
"image": image_url,
77+
"image": image_return,
6578
"seed": validated_input['seed'] + index
6679
})
6780

0 commit comments

Comments
 (0)