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

Cancel fix

Browse files
Files changed (1) hide show
  1. app.py +20 -20
app.py CHANGED
@@ -9,25 +9,6 @@ LOADED_TTF_KEY = "loaded_ttf"
9
  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_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()
30
-
31
  def get_ttf(key: str) -> Optional[any]:
32
  if key in st.session_state:
33
  return st.session_state[key]
@@ -66,9 +47,28 @@ def generate_button(prefix, file_input, version, **kwargs):
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())
73
  st.image(image)
74
 
 
9
  SET_IMG_KEY = "set_img"
10
  OUTPUT_IMG_KEY = "output_img"
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  def get_ttf(key: str) -> Optional[any]:
13
  if key in st.session_state:
14
  return st.session_state[key]
 
47
  key=f"{prefix}-ref_char_ids",
48
  )
49
 
50
+ # For multithreading toggle (prevent function from running too many time)
51
+ process_running = False
52
+ process_thread = None
53
+ cancel_label = st.empty()
54
+
55
+ def toggle_process(process_running, process_thread, run_process):
56
+ if process_running:
57
+ # Toggle off
58
+ process_running = False
59
+ cancel_label.text("Canceled")
60
+ if process_thread: # Kill Thread
61
+ process_thread.join()
62
+ else:
63
+ # Toggle on
64
+ cancel_label.empty()
65
+ process_running = True
66
+ process_thread = Thread(target=run_process)
67
+ process_thread.start()
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(process_running, process_thread, ttf_to_image(file_input, OUTPUT_IMG_KEY, n_samples, ref_char_ids, version) )
72
  set_img(OUTPUT_IMG_KEY, image.copy())
73
  st.image(image)
74