Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ import gradio as gr
|
|
| 2 |
from gradio_client import Client, handle_file
|
| 3 |
import random
|
| 4 |
import os
|
|
|
|
| 5 |
|
| 6 |
# API client for the external Space
|
| 7 |
space_client = Client("prithivMLmods/Qwen-Image-Edit-2511-LoRAs-Fast")
|
|
@@ -30,11 +31,20 @@ LORA_STYLES = [
|
|
| 30 |
MAX_SEED = 2**31 - 1
|
| 31 |
|
| 32 |
def encode_image_to_gallery_dict(image_path):
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
return None
|
| 35 |
try:
|
| 36 |
-
#
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
except Exception as e:
|
| 39 |
print(f"无法读取图片: {image_path}: {e}")
|
| 40 |
return None
|
|
@@ -49,7 +59,7 @@ def infer(
|
|
| 49 |
steps,
|
| 50 |
progress=gr.Progress(track_tqdm=True),
|
| 51 |
):
|
| 52 |
-
# Prepare images_input as a list of dicts
|
| 53 |
images_input = []
|
| 54 |
if image is not None:
|
| 55 |
if isinstance(image, list):
|
|
@@ -84,7 +94,7 @@ def infer(
|
|
| 84 |
print(f" steps: {steps}")
|
| 85 |
|
| 86 |
try:
|
| 87 |
-
# Use plain list of dicts as images parameter
|
| 88 |
result = space_client.predict(
|
| 89 |
images=images_input,
|
| 90 |
prompt=prompt,
|
|
|
|
| 2 |
from gradio_client import Client, handle_file
|
| 3 |
import random
|
| 4 |
import os
|
| 5 |
+
from PIL import Image
|
| 6 |
|
| 7 |
# API client for the external Space
|
| 8 |
space_client = Client("prithivMLmods/Qwen-Image-Edit-2511-LoRAs-Fast")
|
|
|
|
| 31 |
MAX_SEED = 2**31 - 1
|
| 32 |
|
| 33 |
def encode_image_to_gallery_dict(image_path):
|
| 34 |
+
"""
|
| 35 |
+
Returns the dict structure required for GalleryData, containing "image" (binary data) and "orig_name".
|
| 36 |
+
This directly loads the image and provides the binary data instead of a path, fixing the GalleryData validation error.
|
| 37 |
+
"""
|
| 38 |
+
if not image_path or not isinstance(image_path, str) or not os.path.isfile(image_path):
|
| 39 |
return None
|
| 40 |
try:
|
| 41 |
+
# Read image into bytes
|
| 42 |
+
with open(image_path, "rb") as f:
|
| 43 |
+
image_bytes = f.read()
|
| 44 |
+
return {
|
| 45 |
+
"image": image_bytes,
|
| 46 |
+
"orig_name": os.path.basename(image_path)
|
| 47 |
+
}
|
| 48 |
except Exception as e:
|
| 49 |
print(f"无法读取图片: {image_path}: {e}")
|
| 50 |
return None
|
|
|
|
| 59 |
steps,
|
| 60 |
progress=gr.Progress(track_tqdm=True),
|
| 61 |
):
|
| 62 |
+
# Prepare images_input as a list of dicts containing "image" (binary data)
|
| 63 |
images_input = []
|
| 64 |
if image is not None:
|
| 65 |
if isinstance(image, list):
|
|
|
|
| 94 |
print(f" steps: {steps}")
|
| 95 |
|
| 96 |
try:
|
| 97 |
+
# Use plain list of dicts with "image" key as images parameter
|
| 98 |
result = space_client.predict(
|
| 99 |
images=images_input,
|
| 100 |
prompt=prompt,
|