pan-yl commited on
Commit
71d8df5
1 Parent(s): 85ff3b1

update app

Browse files
Files changed (1) hide show
  1. app.py +13 -13
app.py CHANGED
@@ -638,9 +638,9 @@ class ChatBotUI(object):
638
  history_io = history_result[img_id]
639
 
640
  buffered = io.BytesIO()
641
- edit_image[0].save(buffered, format='PNG')
642
  img_b64 = base64.b64encode(buffered.getvalue()).decode('utf-8')
643
- img_str = f'<img src="data:image/png;base64,{img_b64}" style="pointer-events: none;">'
644
  pre_info = f'Received one or more images, so image editing is conducted.\n The first input image @{img_ids[0]} is:\n {img_str}'
645
  else:
646
  pre_info = 'No image ids were found in the provided text prompt, so text-guided image generation is conducted. \n'
@@ -713,7 +713,7 @@ class ChatBotUI(object):
713
  buffered = io.BytesIO()
714
  img.convert('RGB').save(buffered, format='JPEG')
715
  img_b64 = base64.b64encode(buffered.getvalue()).decode('utf-8')
716
- img_str = f'<img src="data:image/png;base64,{img_b64}" style="pointer-events: none;">'
717
 
718
  history.append(
719
  (message,
@@ -831,9 +831,9 @@ class ChatBotUI(object):
831
  edit_task.append('')
832
 
833
  buffered = io.BytesIO()
834
- img.save(buffered, format='PNG')
835
  img_b64 = base64.b64encode(buffered.getvalue()).decode('utf-8')
836
- img_str = f'<img src="data:image/png;base64,{img_b64}" style="pointer-events: none;">'
837
  pre_info = f'Received one or more images, so image editing is conducted.\n The first input image is:\n {img_str}'
838
  else:
839
  pre_info = 'No image ids were found in the provided text prompt, so text-guided image generation is conducted. \n'
@@ -855,7 +855,7 @@ class ChatBotUI(object):
855
  buffered = io.BytesIO()
856
  img.convert('RGB').save(buffered, format='JPEG')
857
  img_b64 = base64.b64encode(buffered.getvalue()).decode('utf-8')
858
- img_str = f'<img src="data:image/png;base64,{img_b64}" style="pointer-events: none;">'
859
  history = [(prompt,
860
  f'{pre_info} The generated image is:\n {img_str}')]
861
  return self.get_history(history), gr.update(value=''), gr.update(
@@ -908,7 +908,7 @@ class ChatBotUI(object):
908
  def edit_image(evt: gr.SelectData):
909
  if isinstance(evt.value, str):
910
  img_b64s = re.findall(
911
- '<img src="data:image/png;base64,(.*?)" style="pointer-events: none;">',
912
  evt.value)
913
  imgs = [
914
  Image.open(io.BytesIO(base64.b64decode(copy.deepcopy(i))))
@@ -1134,14 +1134,14 @@ class ChatBotUI(object):
1134
  thumbnail.save(thumbnail_path, format='JPEG')
1135
 
1136
  buffered = io.BytesIO()
1137
- img.convert('RGB').save(buffered, format='PNG')
1138
  img_b64 = base64.b64encode(buffered.getvalue()).decode('utf-8')
1139
- img_str = f'<img src="data:image/png;base64,{img_b64}" style="pointer-events: none;">'
1140
 
1141
  buffered = io.BytesIO()
1142
- mask.convert('RGB').save(buffered, format='PNG')
1143
  mask_b64 = base64.b64encode(buffered.getvalue()).decode('utf-8')
1144
- mask_str = f'<img src="data:image/png;base64,{mask_b64}" style="pointer-events: none;">'
1145
 
1146
  images[img_id] = {
1147
  'image': save_path,
@@ -1190,9 +1190,9 @@ class ChatBotUI(object):
1190
  }
1191
 
1192
  buffered = io.BytesIO()
1193
- img.convert('RGB').save(buffered, format='PNG')
1194
  img_b64 = base64.b64encode(buffered.getvalue()).decode('utf-8')
1195
- img_str = f'<img src="data:image/png;base64,{img_b64}" style="pointer-events: none;">'
1196
 
1197
  history.append(
1198
  (None,
 
638
  history_io = history_result[img_id]
639
 
640
  buffered = io.BytesIO()
641
+ edit_image[0].save(buffered, format='JPEG')
642
  img_b64 = base64.b64encode(buffered.getvalue()).decode('utf-8')
643
+ img_str = f'<img src="data:image/jpg;base64,{img_b64}" style="pointer-events: none;">'
644
  pre_info = f'Received one or more images, so image editing is conducted.\n The first input image @{img_ids[0]} is:\n {img_str}'
645
  else:
646
  pre_info = 'No image ids were found in the provided text prompt, so text-guided image generation is conducted. \n'
 
713
  buffered = io.BytesIO()
714
  img.convert('RGB').save(buffered, format='JPEG')
715
  img_b64 = base64.b64encode(buffered.getvalue()).decode('utf-8')
716
+ img_str = f'<img src="data:image/jpg;base64,{img_b64}" style="pointer-events: none;">'
717
 
718
  history.append(
719
  (message,
 
831
  edit_task.append('')
832
 
833
  buffered = io.BytesIO()
834
+ img.save(buffered, format='JPEG')
835
  img_b64 = base64.b64encode(buffered.getvalue()).decode('utf-8')
836
+ img_str = f'<img src="data:image/jpg;base64,{img_b64}" style="pointer-events: none;">'
837
  pre_info = f'Received one or more images, so image editing is conducted.\n The first input image is:\n {img_str}'
838
  else:
839
  pre_info = 'No image ids were found in the provided text prompt, so text-guided image generation is conducted. \n'
 
855
  buffered = io.BytesIO()
856
  img.convert('RGB').save(buffered, format='JPEG')
857
  img_b64 = base64.b64encode(buffered.getvalue()).decode('utf-8')
858
+ img_str = f'<img src="data:image/jpg;base64,{img_b64}" style="pointer-events: none;">'
859
  history = [(prompt,
860
  f'{pre_info} The generated image is:\n {img_str}')]
861
  return self.get_history(history), gr.update(value=''), gr.update(
 
908
  def edit_image(evt: gr.SelectData):
909
  if isinstance(evt.value, str):
910
  img_b64s = re.findall(
911
+ '<img src="data:image/jpg;base64,(.*?)" style="pointer-events: none;">',
912
  evt.value)
913
  imgs = [
914
  Image.open(io.BytesIO(base64.b64decode(copy.deepcopy(i))))
 
1134
  thumbnail.save(thumbnail_path, format='JPEG')
1135
 
1136
  buffered = io.BytesIO()
1137
+ img.convert('RGB').save(buffered, format='JPEG')
1138
  img_b64 = base64.b64encode(buffered.getvalue()).decode('utf-8')
1139
+ img_str = f'<img src="data:image/jpg;base64,{img_b64}" style="pointer-events: none;">'
1140
 
1141
  buffered = io.BytesIO()
1142
+ mask.convert('RGB').save(buffered, format='JPEG')
1143
  mask_b64 = base64.b64encode(buffered.getvalue()).decode('utf-8')
1144
+ mask_str = f'<img src="data:image/jpg;base64,{mask_b64}" style="pointer-events: none;">'
1145
 
1146
  images[img_id] = {
1147
  'image': save_path,
 
1190
  }
1191
 
1192
  buffered = io.BytesIO()
1193
+ img.convert('RGB').save(buffered, format='JPEG')
1194
  img_b64 = base64.b64encode(buffered.getvalue()).decode('utf-8')
1195
+ img_str = f'<img src="data:image/jpg;base64,{img_b64}" style="pointer-events: none;">'
1196
 
1197
  history.append(
1198
  (None,