myn0908 commited on
Commit
eb58e8d
1 Parent(s): 3982e62

update clear flag

Browse files
Files changed (1) hide show
  1. app.py +19 -14
app.py CHANGED
@@ -47,7 +47,7 @@ def get_dark_mode():
47
  def clear_session():
48
  global clear_flag
49
  clear_flag = True
50
- return None, None
51
 
52
 
53
  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):
@@ -89,24 +89,29 @@ def convert_to_pencil_sketch(image):
89
  return pencil_sketch
90
 
91
  def get_meta_from_image(input_img, type_image):
92
- if input_img is None:
93
- return gr.update(value=None)
 
 
 
 
 
94
 
95
- img = Image.open(BytesIO(requests.get(input_img).content)).convert('RGB')
96
 
97
- # Read the image using Pillow
98
- img_np = np.array(img)
99
 
100
- if type_image == 'RGB':
101
- sketch = convert_to_pencil_sketch(img_np)
102
- processed_img = 255 - sketch
103
- elif type_image == 'SKETCH':
104
- processed_img = 255 - img_np
105
 
106
- # Convert the processed image back to PIL Image
107
- img_pil = Image.fromarray(processed_img.astype('uint8'))
108
 
109
- return img_pil
110
 
111
 
112
  with gr.Blocks(css=css, theme="NoCrypt/miku@1.2.1") as demo:
 
47
  def clear_session():
48
  global clear_flag
49
  clear_flag = True
50
+ return gr.update(value=None), gr.update(value=None)
51
 
52
 
53
  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):
 
89
  return pencil_sketch
90
 
91
  def get_meta_from_image(input_img, type_image):
92
+ global clear_flag
93
+ if clear_flag:
94
+ clear_flag = False # Reset the flag after handling the clear action
95
+ return gr.update(value=None) # Ensure nothing is processed if clear flag is true
96
+ else:
97
+ if input_img is None:
98
+ return gr.update(value=None)
99
 
100
+ img = Image.open(BytesIO(requests.get(input_img).content)).convert('RGB')
101
 
102
+ # Read the image using Pillow
103
+ img_np = np.array(img)
104
 
105
+ if type_image == 'RGB':
106
+ sketch = convert_to_pencil_sketch(img_np)
107
+ processed_img = 255 - sketch
108
+ elif type_image == 'SKETCH':
109
+ processed_img = 255 - img_np
110
 
111
+ # Convert the processed image back to PIL Image
112
+ img_pil = Image.fromarray(processed_img.astype('uint8'))
113
 
114
+ return img_pil
115
 
116
 
117
  with gr.Blocks(css=css, theme="NoCrypt/miku@1.2.1") as demo: