ParahumanSkitter commited on
Commit
7a929de
·
verified ·
1 Parent(s): 76ac0b7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -8
app.py CHANGED
@@ -33,31 +33,39 @@ def update_imgbox(choices):
33
  choices_plus = extend_choices(choices)
34
  return [gr.Image(None, label=m, visible=(m != 'NA'), elem_id="custom_image") for m in choices_plus]
35
 
36
- def gen_fn(model_str, prompt, negative_prompt, max_retries=10):
37
  if model_str == 'NA':
38
  return None
39
 
40
  retries = 0
 
41
  while retries < max_retries:
42
  try:
43
  noise = str(randint(0, 9999999))
 
 
 
 
 
44
  if hasattr(models_load[model_str], 'negative_prompt'):
45
  result = models_load[model_str](f'{prompt} {noise}', negative_prompt=negative_prompt)
46
  else:
47
  result = models_load[model_str](f'{prompt} {noise}')
48
- return result
 
49
  except Exception as e:
50
  # Check for specific error messages or status codes
51
  if "CUDA out of memory" in str(e) or "500" in str(e):
52
- print(f"CUDA out of memory or server error: {e}")
53
  else:
54
- print(f"Error generating image: {e}")
55
 
56
  retries += 1
57
  if retries >= max_retries:
58
- raise Exception(f"Failed to generate image after {max_retries} retries.")
 
59
 
60
- return None
61
 
62
  def make_me():
63
  with gr.Row():
@@ -79,9 +87,11 @@ def make_me():
79
 
80
  with gr.Row():
81
  output = [gr.Image(label=m, min_width=250, height=250, elem_id="custom_image") for m in default_models]
 
 
82
  current_models = [gr.Textbox(m, visible=False) for m in default_models]
83
- for m, o in zip(current_models, output):
84
- gen_event = gen_button.click(gen_fn, [m, txt_input, negative_txt_input], o)
85
  stop_button.click(on_stop_click, inputs=None, outputs=[gen_button, stop_button], cancels=[gen_event])
86
 
87
  with gr.Accordion('Model selection', elem_id="custom_accordion"):
@@ -230,6 +240,17 @@ body {
230
  width: 100%;
231
  box-sizing: border-box;
232
  }
 
 
 
 
 
 
 
 
 
 
 
233
  @media (max-width: 768px) {
234
  .gradio-container {
235
  width: 100%;
 
33
  choices_plus = extend_choices(choices)
34
  return [gr.Image(None, label=m, visible=(m != 'NA'), elem_id="custom_image") for m in choices_plus]
35
 
36
+ def gen_fn(model_str, prompt, negative_prompt, max_retries=10, progress=gr.Progress()):
37
  if model_str == 'NA':
38
  return None
39
 
40
  retries = 0
41
+ feedback = ""
42
  while retries < max_retries:
43
  try:
44
  noise = str(randint(0, 9999999))
45
+ with progress(tracker=True) as pbar:
46
+ for step in range(1, 101):
47
+ time.sleep(0.05) # Simulate work being done
48
+ pbar(step / 100)
49
+
50
  if hasattr(models_load[model_str], 'negative_prompt'):
51
  result = models_load[model_str](f'{prompt} {noise}', negative_prompt=negative_prompt)
52
  else:
53
  result = models_load[model_str](f'{prompt} {noise}')
54
+ feedback += f"{get_current_time()} - Attempt {retries + 1}: Success for {model_str}\n"
55
+ return result, feedback
56
  except Exception as e:
57
  # Check for specific error messages or status codes
58
  if "CUDA out of memory" in str(e) or "500" in str(e):
59
+ feedback += f"{get_current_time()} - CUDA out of memory or server error for {model_str}: {e}\n"
60
  else:
61
+ feedback += f"{get_current_time()} - Error generating image for {model_str}: {e}\n"
62
 
63
  retries += 1
64
  if retries >= max_retries:
65
+ feedback += f"{get_current_time()} - Failed to generate image after {max_retries} retries for {model_str}\n"
66
+ raise Exception(f"Failed to generate image after {max_retries} retries for {model_str}.")
67
 
68
+ return None, feedback
69
 
70
  def make_me():
71
  with gr.Row():
 
87
 
88
  with gr.Row():
89
  output = [gr.Image(label=m, min_width=250, height=250, elem_id="custom_image") for m in default_models]
90
+ progress_bars = [gr.Progress(label=f"Progress for {m}", visible=(m != 'NA')) for m in default_models]
91
+ feedback_box = gr.Textbox(label="Feedback", lines=10, interactive=False, elem_id="custom_feedback_box")
92
  current_models = [gr.Textbox(m, visible=False) for m in default_models]
93
+ for m, o, p, c in zip(current_models, output, progress_bars, default_models):
94
+ gen_event = gen_button.click(gen_fn, [m, txt_input, negative_txt_input, gr.Slider(1, 10, value=10, label="Max Retries"), p], [o, feedback_box], cancels=[gen_event])
95
  stop_button.click(on_stop_click, inputs=None, outputs=[gen_button, stop_button], cancels=[gen_event])
96
 
97
  with gr.Accordion('Model selection', elem_id="custom_accordion"):
 
240
  width: 100%;
241
  box-sizing: border-box;
242
  }
243
+ .custom_feedback_box {
244
+ background-color: #2d343f;
245
+ border: 1px solid #3b4252;
246
+ color: #7f8184;
247
+ padding: 10px;
248
+ border-radius: 4px;
249
+ margin-top: 10px;
250
+ width: 100%;
251
+ box-sizing: border-box;
252
+ overflow-y: auto;
253
+ }
254
  @media (max-width: 768px) {
255
  .gradio-container {
256
  width: 100%;