Skip to content

Commit

Permalink
Bugfix variable reference before assignment
Browse files Browse the repository at this point in the history
Prevent non-valid image paths in ImageReward.score resulting in
local variable 'pil_image' referenced before assignment
  • Loading branch information
AniAggarwal committed Sep 24, 2024
1 parent 8cfdfb9 commit c69c0f9
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions ImageReward/ImageReward.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,8 @@ def score(self, prompt, image):
# image encode
if isinstance(image, Image.Image):
pil_image = image
elif isinstance(image, str):
if os.path.isfile(image):
pil_image = Image.open(image)
elif isinstance(image, str) and os.path.isfile(image):
pil_image = Image.open(image)
else:
raise TypeError(r'This image parameter type has not been supportted yet. Please pass PIL.Image or file path str.')

Expand Down

0 comments on commit c69c0f9

Please sign in to comment.