Spaces:
Running
Running
pass base64 images
Browse files- app_dialogue.py +13 -2
app_dialogue.py
CHANGED
@@ -106,6 +106,17 @@ def pil_to_temp_file(
|
|
106 |
return filename
|
107 |
|
108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
def add_file_gallery(selected_state: gr.SelectData, gallery_list: List[str]):
|
110 |
return (
|
111 |
"Write a meme about this image.",
|
@@ -320,8 +331,8 @@ def prompt_list_to_tgi_input(prompt_list: List[str]) -> str:
|
|
320 |
print(f"Image is not loading")
|
321 |
else:
|
322 |
elem_pil = Image.open(elem)
|
323 |
-
|
324 |
-
result_string_input += f"![]({
|
325 |
else:
|
326 |
result_string_input += elem
|
327 |
return result_string_input
|
|
|
106 |
return filename
|
107 |
|
108 |
|
109 |
+
def pil_to_base64(
|
110 |
+
img: PIL.Image.Image,
|
111 |
+
resize: bool = False,
|
112 |
+
) -> str:
|
113 |
+
"""Save a PIL image into a temp file"""
|
114 |
+
if resize:
|
115 |
+
img = img.resize((224, 224), Image.LANCZOS)
|
116 |
+
base64_img = processing_utils.encode_pil_to_base64(img)
|
117 |
+
return base64_img
|
118 |
+
|
119 |
+
|
120 |
def add_file_gallery(selected_state: gr.SelectData, gallery_list: List[str]):
|
121 |
return (
|
122 |
"Write a meme about this image.",
|
|
|
331 |
print(f"Image is not loading")
|
332 |
else:
|
333 |
elem_pil = Image.open(elem)
|
334 |
+
base64_img = pil_to_base64(elem_pil, resize=True)
|
335 |
+
result_string_input += f"![]({base64_img})"
|
336 |
else:
|
337 |
result_string_input += elem
|
338 |
return result_string_input
|