kenfoo commited on
Commit
921080d
·
verified ·
1 Parent(s): 7e04244

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -14
app.py CHANGED
@@ -1,8 +1,7 @@
1
  import gradio as gr
2
- from gradio_client import Client
3
  import random
4
  import os
5
- import base64
6
 
7
  # API client for the external Space
8
  space_client = Client("prithivMLmods/Qwen-Image-Edit-2511-LoRAs-Fast")
@@ -28,23 +27,15 @@ LORA_STYLES = [
28
  'Studio-DeLight',
29
  'Cinematic-FlatLog',
30
  ]
31
- MAX_SEED = 2**32 - 1
32
 
33
  def encode_image_to_gallery_dict(image_path):
34
- """
35
- Read image file and encode as a dictionary suitable for the Hugging Face Space GalleryData API.
36
- It must be {"image": {"data": <base64 str>}} for image input.
37
- """
38
  if not image_path or not isinstance(image_path, str):
39
  return None
40
  try:
41
- with open(image_path, "rb") as f:
42
- img_bytes = f.read()
43
- b64_str = base64.b64encode(img_bytes).decode("utf-8")
44
- # API expects: {"image": {"data": <base64 str>}}
45
- return {"image": {"data": b64_str}}
46
  except Exception as e:
47
- print(f"无法读取图片或编码失败: {image_path}: {e}")
48
  return None
49
 
50
  def infer(
@@ -82,7 +73,7 @@ def infer(
82
  seed = random.randint(0, MAX_SEED)
83
 
84
  print("[调用API] space_client.predict 输入参数:")
85
- print(f" images (base64 bytes): {[len(i['image']['data']) for i in images_input]}")
86
  print(f" prompt: {prompt}")
87
  print(f" lora_adapter: {lora_adapter}")
88
  print(f" seed: {seed}")
 
1
  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")
 
27
  'Studio-DeLight',
28
  'Cinematic-FlatLog',
29
  ]
30
+ MAX_SEED = 2**31 - 1
31
 
32
  def encode_image_to_gallery_dict(image_path):
 
 
 
 
33
  if not image_path or not isinstance(image_path, str):
34
  return None
35
  try:
36
+ return {"image": handle_file(image_path), "caption": None}
 
 
 
 
37
  except Exception as e:
38
+ print(f"无法读取图片: {image_path}: {e}")
39
  return None
40
 
41
  def infer(
 
73
  seed = random.randint(0, MAX_SEED)
74
 
75
  print("[调用API] space_client.predict 输入参数:")
76
+ print(f" images count: {len(images_input)}")
77
  print(f" prompt: {prompt}")
78
  print(f" lora_adapter: {lora_adapter}")
79
  print(f" seed: {seed}")