Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -54,23 +54,23 @@ def generate(
|
|
| 54 |
if not prompt or not prompt.strip():
|
| 55 |
raise gr.Error("Please provide a text instruction.")
|
| 56 |
|
| 57 |
-
# Gradio Gallery returns list of
|
| 58 |
from PIL import Image
|
| 59 |
|
| 60 |
if isinstance(images, list):
|
| 61 |
pil_images = []
|
| 62 |
for img in images:
|
| 63 |
if isinstance(img, dict):
|
| 64 |
-
# Gallery passes {'image': filepath, 'caption': ...} or {'path': ...}
|
| 65 |
path = img.get("image") or img.get("path")
|
| 66 |
if path:
|
| 67 |
pil_images.append(Image.open(path).convert("RGB"))
|
|
|
|
|
|
|
|
|
|
| 68 |
elif isinstance(img, str):
|
| 69 |
pil_images.append(Image.open(img).convert("RGB"))
|
| 70 |
elif isinstance(img, Image.Image):
|
| 71 |
pil_images.append(img.convert("RGB"))
|
| 72 |
-
else:
|
| 73 |
-
pil_images.append(Image.open(img).convert("RGB"))
|
| 74 |
elif isinstance(images, str):
|
| 75 |
pil_images = [Image.open(images).convert("RGB")]
|
| 76 |
else:
|
|
|
|
| 54 |
if not prompt or not prompt.strip():
|
| 55 |
raise gr.Error("Please provide a text instruction.")
|
| 56 |
|
| 57 |
+
# Gradio Gallery returns list of (filepath, caption) tuples, dicts, or strings
|
| 58 |
from PIL import Image
|
| 59 |
|
| 60 |
if isinstance(images, list):
|
| 61 |
pil_images = []
|
| 62 |
for img in images:
|
| 63 |
if isinstance(img, dict):
|
|
|
|
| 64 |
path = img.get("image") or img.get("path")
|
| 65 |
if path:
|
| 66 |
pil_images.append(Image.open(path).convert("RGB"))
|
| 67 |
+
elif isinstance(img, (tuple, list)) and len(img) > 0:
|
| 68 |
+
path = img[0]
|
| 69 |
+
pil_images.append(Image.open(path).convert("RGB"))
|
| 70 |
elif isinstance(img, str):
|
| 71 |
pil_images.append(Image.open(img).convert("RGB"))
|
| 72 |
elif isinstance(img, Image.Image):
|
| 73 |
pil_images.append(img.convert("RGB"))
|
|
|
|
|
|
|
| 74 |
elif isinstance(images, str):
|
| 75 |
pil_images = [Image.open(images).convert("RGB")]
|
| 76 |
else:
|