microhum commited on
Commit
734d298
·
1 Parent(s): fcb5dc8

add showing cancel

Browse files
Files changed (1) hide show
  1. app.py +7 -5
app.py CHANGED
@@ -10,18 +10,20 @@ SET_IMG_KEY = "set_img"
10
  OUTPUT_IMG_KEY = "output_img"
11
 
12
  # For multithreading toggle (prevent function from running too many time)
13
- process_runnning = False
14
  process_thread = None
 
15
 
16
  def toggle_process(process_running, process_thread, run_process):
17
- if process_runnning:
18
  # Toggle off
19
  process_running = False
20
- st.write("Cancled")
21
  if process_thread: # Kill Thread
22
  process_thread.join()
23
  else:
24
  # Toggle on
 
25
  process_running = True
26
  process_thread = Thread(target=run_process)
27
  process_thread.start()
@@ -63,8 +65,8 @@ def generate_button(prefix, file_input, version, **kwargs):
63
  value="1,2,3,4,5,6,7,8",
64
  key=f"{prefix}-ref_char_ids",
65
  )
66
-
67
- if st.button("Generate image", key=f"{prefix}-btn"):
68
  with st.spinner(f"⏳ Generating image (5 minutes per n_sample estimated time)"):
69
  image = toggle_process( ttf_to_image(file_input, OUTPUT_IMG_KEY, n_samples, ref_char_ids, version) )
70
  set_img(OUTPUT_IMG_KEY, image.copy())
 
10
  OUTPUT_IMG_KEY = "output_img"
11
 
12
  # For multithreading toggle (prevent function from running too many time)
13
+ process_running = False
14
  process_thread = None
15
+ cancel_label = st.empty()
16
 
17
  def toggle_process(process_running, process_thread, run_process):
18
+ if process_running:
19
  # Toggle off
20
  process_running = False
21
+ cancel_label.text("Canceled")
22
  if process_thread: # Kill Thread
23
  process_thread.join()
24
  else:
25
  # Toggle on
26
+ cancel_label.empty()
27
  process_running = True
28
  process_thread = Thread(target=run_process)
29
  process_thread.start()
 
65
  value="1,2,3,4,5,6,7,8",
66
  key=f"{prefix}-ref_char_ids",
67
  )
68
+
69
+ if st.button("Generate image", key=f"{prefix}-btn") and process_running == False:
70
  with st.spinner(f"⏳ Generating image (5 minutes per n_sample estimated time)"):
71
  image = toggle_process( ttf_to_image(file_input, OUTPUT_IMG_KEY, n_samples, ref_char_ids, version) )
72
  set_img(OUTPUT_IMG_KEY, image.copy())