sunbv56 commited on
Commit
96a99a3
·
verified ·
1 Parent(s): 4dc29a3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -5
app.py CHANGED
@@ -67,10 +67,14 @@ async def generate_image(image_bytes, text_input):
67
  )
68
 
69
  images = []
70
- for part in response.candidates[0].content.parts:
71
- if part.inline_data is not None:
72
- img = Image.open(BytesIO(part.inline_data.data))
73
- images.append(img)
 
 
 
 
74
  return images
75
 
76
  async def process_request(image, text, num_requests):
@@ -81,7 +85,7 @@ async def process_request(image, text, num_requests):
81
 
82
  # Hợp nhất danh sách ảnh từ các request
83
  original_images = [img for result in results for img in result]
84
- resized_images = [img.resize((2560, 1440), Image.ANTIALIAS) for img in original_images] # Resize trước khi upscale
85
  srcnn_images = [upscale_image(img) for img in resized_images]
86
 
87
  return original_images + srcnn_images # 4 ảnh gốc + 4 ảnh đã qua SRCNN
 
67
  )
68
 
69
  images = []
70
+ if response and response.candidates and response.candidates[0].content:
71
+ for part in response.candidates[0].content.parts:
72
+ if part.inline_data is not None:
73
+ img = Image.open(BytesIO(part.inline_data.data))
74
+ images.append(img)
75
+ else:
76
+ print("⚠️ Gemini API không trả về kết quả hợp lệ!")
77
+
78
  return images
79
 
80
  async def process_request(image, text, num_requests):
 
85
 
86
  # Hợp nhất danh sách ảnh từ các request
87
  original_images = [img for result in results for img in result]
88
+ resized_images = [img.resize((2560, 1440), Image.LANCZOS) for img in original_images] # Resize trước khi upscale
89
  srcnn_images = [upscale_image(img) for img in resized_images]
90
 
91
  return original_images + srcnn_images # 4 ảnh gốc + 4 ảnh đã qua SRCNN