mirror of
https://github.com/oobabooga/text-generation-webui.git
synced 2024-11-22 08:07:56 +01:00
API: Properly handle Images with RGBA color format (#5332)
This commit is contained in:
parent
db1da9f98d
commit
166fdf09f3
@ -156,8 +156,9 @@ def convert_history(history):
|
|||||||
img = Image.open(BytesIO(my_res.content))
|
img = Image.open(BytesIO(my_res.content))
|
||||||
except Exception:
|
except Exception:
|
||||||
raise 'Image cannot be loaded from the URL!'
|
raise 'Image cannot be loaded from the URL!'
|
||||||
|
|
||||||
buffered = BytesIO()
|
buffered = BytesIO()
|
||||||
|
if img.mode in ("RGBA", "P"):
|
||||||
|
img = img.convert("RGB")
|
||||||
img.save(buffered, format="JPEG")
|
img.save(buffered, format="JPEG")
|
||||||
img_str = base64.b64encode(buffered.getvalue()).decode('utf-8')
|
img_str = base64.b64encode(buffered.getvalue()).decode('utf-8')
|
||||||
content = f'<img src="data:image/jpeg;base64,{img_str}">'
|
content = f'<img src="data:image/jpeg;base64,{img_str}">'
|
||||||
|
Loading…
Reference in New Issue
Block a user