This repository was archived by the owner on May 8, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Original file line number Diff line number Diff line change 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
76diffusers == 0.12.1
87torch == 1.13.1 --extra-index-url=https://download.pytorch.org/whl/cu116
Original file line number Diff line number Diff line change 11''' infer.py for runpod worker '''
22
33import os
4+ import base64
45import predict
56import argparse
67
1213from 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+
1528def 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
You can’t perform that action at this time.
0 commit comments