myn0908 commited on
Commit
8904099
1 Parent(s): f66f514

fixing code

Browse files
Files changed (1) hide show
  1. app.py +10 -2
app.py CHANGED
@@ -1,5 +1,6 @@
1
- import os
2
  import numpy as np
 
3
  import io
4
  import requests
5
  from io import BytesIO
@@ -43,12 +44,19 @@ def get_dark_mode():
43
  document.body.classList.toggle('dark');
44
  }
45
  """
 
 
 
 
 
 
46
 
47
  def clear_session(image):
48
  global clear_flag
49
  clear_flag = True
50
  ones = Image.new("L", (1024, 1024), 255)
51
- return ones, gr.update(value=None)
 
52
 
53
 
54
  def assign_gpu(options, img_init, text_init, prompt_template_init, style_name_init, seeds_init, val_r_values_init, faster_init, model_name_init, input_type):
 
1
+ import os
2
  import numpy as np
3
+ import base64
4
  import io
5
  import requests
6
  from io import BytesIO
 
44
  document.body.classList.toggle('dark');
45
  }
46
  """
47
+
48
+ def pil_image_to_data_uri(img, format="PNG"):
49
+ buffered = BytesIO()
50
+ img.save(buffered, format=format)
51
+ img_str = base64.b64encode(buffered.getvalue()).decode()
52
+ return f"data:image/{format.lower()};base64,{img_str}"
53
 
54
  def clear_session(image):
55
  global clear_flag
56
  clear_flag = True
57
  ones = Image.new("L", (1024, 1024), 255)
58
+ temp_uri = pil_image_to_data_uri(ones)
59
+ return gr.update(link=temp_uri), gr.update(value=None)
60
 
61
 
62
  def assign_gpu(options, img_init, text_init, prompt_template_init, style_name_init, seeds_init, val_r_values_init, faster_init, model_name_init, input_type):