Spaces:
Build error
Build error
Update app_dialogue.py
Browse files- app_dialogue.py +21 -12
app_dialogue.py
CHANGED
|
@@ -69,6 +69,8 @@ from PIL import Image
|
|
| 69 |
import tempfile
|
| 70 |
|
| 71 |
def convert_to_rgb_pil(image):
|
|
|
|
|
|
|
| 72 |
if image.mode == "RGB":
|
| 73 |
return image
|
| 74 |
|
|
@@ -82,12 +84,16 @@ def convert_to_rgb_pil(image):
|
|
| 82 |
temp_file_path = temp_file.name
|
| 83 |
alpha_composite.save(temp_file_path)
|
| 84 |
temp_file.close()
|
|
|
|
| 85 |
return temp_file_path # Return the path to the saved image
|
| 86 |
|
| 87 |
|
| 88 |
def convert_to_rgb(filepath_or_pilimg):
|
| 89 |
# `image.convert("RGB")` would only work for .jpg images, as it creates a wrong background
|
| 90 |
# for transparent images. The call to `alpha_composite` handles this case
|
|
|
|
|
|
|
|
|
|
| 91 |
if isinstance(filepath_or_pilimg, PIL.Image.Image):
|
| 92 |
return convert_to_rgb_pil(filepath_or_pilimg)
|
| 93 |
with Image.open(filepath_or_pilimg) as image:
|
|
@@ -113,6 +119,7 @@ def convert_to_rgb(filepath_or_pilimg):
|
|
| 113 |
alpha_composite.save(temp_file_path)
|
| 114 |
temp_file.close()
|
| 115 |
|
|
|
|
| 116 |
return temp_file_path # Return the path to the saved image
|
| 117 |
|
| 118 |
def pil_to_markdown_im(image):
|
|
@@ -275,17 +282,19 @@ def user_prompt_list_to_markdown(user_prompt_list: List[Union[str, PIL.Image.Ima
|
|
| 275 |
for elem in user_prompt_list:
|
| 276 |
print(f"inside user_prompt_list_to_markdown, for loop on user_prompt_list")
|
| 277 |
print(f"elem is - {elem} ")
|
| 278 |
-
if isinstance(elem, str)
|
| 279 |
-
|
| 280 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 281 |
#elif isinstance(elem, str) and "/tmp/gradio/" in elem:
|
| 282 |
# resulting_string += f"})" #f""
|
| 283 |
# print(f"inside first ELIF - when elem is string and is the temp image filepath. resulting_string is - {resulting_string}")
|
| 284 |
-
elif isinstance(elem, PIL.Image.Image) or "/tmp/gradio/" in elem: #and "/tmp/gradio/" in elem:
|
| 285 |
-
resulting_string +=
|
| 286 |
-
print(f"inside the ELIF - when elem is an instance of PIL.Image.Image
|
| 287 |
-
elif isinstance(elem, str) and "/tmp/gradio/" in elem:
|
| 288 |
-
resulting_string += f"})"
|
| 289 |
else:
|
| 290 |
raise ValueError(
|
| 291 |
"Unknown type for `user_prompt_list`. Expected an element of type `str` or `PIL.Image.Image` and got"
|
|
@@ -1015,10 +1024,10 @@ And so, the story of Mulan and Shrek's romance came to an end, leaving a lasting
|
|
| 1015 |
gr.Examples(
|
| 1016 |
examples=[
|
| 1017 |
["What are the armed baguettes guarding?", f"{examples_path}/example_images/baguettes_guarding_paris.png"],
|
| 1018 |
-
|
| 1019 |
-
|
| 1020 |
-
|
| 1021 |
-
|
| 1022 |
# ["Can you describe the image?", f"{examples_path}/example_images/bear_costume.png"],
|
| 1023 |
# ["What is this animal and why is it unusual?", f"{examples_path}/example_images/blue_dog.png"],
|
| 1024 |
# [
|
|
|
|
| 69 |
import tempfile
|
| 70 |
|
| 71 |
def convert_to_rgb_pil(image):
|
| 72 |
+
print(f"***** convert_to_rgb_pil ******")
|
| 73 |
+
print(f"params: image is - {image}")
|
| 74 |
if image.mode == "RGB":
|
| 75 |
return image
|
| 76 |
|
|
|
|
| 84 |
temp_file_path = temp_file.name
|
| 85 |
alpha_composite.save(temp_file_path)
|
| 86 |
temp_file.close()
|
| 87 |
+
print(f"# Return the path to the saved image as - {temp_file_path}")
|
| 88 |
return temp_file_path # Return the path to the saved image
|
| 89 |
|
| 90 |
|
| 91 |
def convert_to_rgb(filepath_or_pilimg):
|
| 92 |
# `image.convert("RGB")` would only work for .jpg images, as it creates a wrong background
|
| 93 |
# for transparent images. The call to `alpha_composite` handles this case
|
| 94 |
+
print(f"***** convert_to_rgb ******")
|
| 95 |
+
print(f"params: image is - {filepath_or_pilimg}")
|
| 96 |
+
|
| 97 |
if isinstance(filepath_or_pilimg, PIL.Image.Image):
|
| 98 |
return convert_to_rgb_pil(filepath_or_pilimg)
|
| 99 |
with Image.open(filepath_or_pilimg) as image:
|
|
|
|
| 119 |
alpha_composite.save(temp_file_path)
|
| 120 |
temp_file.close()
|
| 121 |
|
| 122 |
+
print(f"# Return the path to the saved image as - {temp_file_path}")
|
| 123 |
return temp_file_path # Return the path to the saved image
|
| 124 |
|
| 125 |
def pil_to_markdown_im(image):
|
|
|
|
| 282 |
for elem in user_prompt_list:
|
| 283 |
print(f"inside user_prompt_list_to_markdown, for loop on user_prompt_list")
|
| 284 |
print(f"elem is - {elem} ")
|
| 285 |
+
if isinstance(elem, str):
|
| 286 |
+
if "/tmp/gradio/" not in elem:
|
| 287 |
+
resulting_string += elem
|
| 288 |
+
print(f"inside IF - when elem is string and is not temp image filepath. resulting_string is - {resulting_string}")
|
| 289 |
+
elif "/tmp/gradio/" in elem:
|
| 290 |
+
resulting_string += f"})"
|
| 291 |
+
print(f"inside IF - when elem is string and is a temp image filepath. resulting_string is - {resulting_string}")
|
| 292 |
#elif isinstance(elem, str) and "/tmp/gradio/" in elem:
|
| 293 |
# resulting_string += f"})" #f""
|
| 294 |
# print(f"inside first ELIF - when elem is string and is the temp image filepath. resulting_string is - {resulting_string}")
|
| 295 |
+
elif isinstance(elem, PIL.Image.Image): #or "/tmp/gradio/" in elem: #and "/tmp/gradio/" in elem:
|
| 296 |
+
resulting_string += f"})" #pil_to_markdown_im(convert_to_rgb(elem)) <---------------
|
| 297 |
+
print(f"inside the ELIF - when elem is an instance of PIL.Image.Image. The resulting_string after convert_to_rgb() operation is - {resulting_string}")
|
|
|
|
|
|
|
| 298 |
else:
|
| 299 |
raise ValueError(
|
| 300 |
"Unknown type for `user_prompt_list`. Expected an element of type `str` or `PIL.Image.Image` and got"
|
|
|
|
| 1024 |
gr.Examples(
|
| 1025 |
examples=[
|
| 1026 |
["What are the armed baguettes guarding?", f"{examples_path}/example_images/baguettes_guarding_paris.png"],
|
| 1027 |
+
[
|
| 1028 |
+
"Can you tell me a very short story based on this image?",
|
| 1029 |
+
f"{examples_path}/example_images/chicken_on_money.png",
|
| 1030 |
+
],
|
| 1031 |
# ["Can you describe the image?", f"{examples_path}/example_images/bear_costume.png"],
|
| 1032 |
# ["What is this animal and why is it unusual?", f"{examples_path}/example_images/blue_dog.png"],
|
| 1033 |
# [
|