DazDin commited on
Commit
7afe24b
·
verified ·
1 Parent(s): 676e1c4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -32
app.py CHANGED
@@ -2,17 +2,18 @@ import gradio as gr
2
  from random import randint
3
  from all_models import models
4
 
5
- models_load = {}
6
- def load_models():
7
  global models_load
 
8
  for model in models:
9
- try:
10
- models_load[model] = gr.Interface.load(f'models/{model}')
11
- except Exception as error:
12
- print(f"Failed to load model {model}: {error}")
13
- models_load[model] = gr.Interface(lambda txt: None, ['text'], ['image'])
 
14
 
15
- load_models()
16
 
17
  num_models = len(models)
18
  default_models = models[:num_models]
@@ -27,31 +28,25 @@ def update_imgbox(choices):
27
  def gen_fn(model_str, prompt):
28
  if model_str == 'NA':
29
  return None
30
- noise = str(randint(0, 99999999))
31
- return models_load[model_str](f'{prompt} {noise}').outputs[0]
32
 
33
  def make_me():
34
  with gr.Row():
35
- txt_input = gr.Textbox(label='Your prompt:', lines=3, container=False, elem_id="custom_textbox", placeholder="Prompt")
36
- gen_button = gr.Button('Generate images', elem_id="custom_gen_button")
37
- stop_button = gr.Button('Stop', variant='secondary', interactive=False, elem_id="custom_stop_button")
38
-
39
- def on_generate_click():
40
- nonlocal gen_button, stop_button
41
- gen_button.interactive = True
42
- stop_button.interactive = True
43
- gen_button.label = 'Generating...'
44
- stop_button.label = 'Stop'
45
-
46
- def on_stop_click():
47
- nonlocal gen_button, stop_button
48
- gen_button.interactive = False
49
- stop_button.interactive = False
50
- gen_button.label = 'Generate images'
51
- stop_button.label = 'Stopped'
52
-
53
- gen_button.click(on_generate_click, inputs=None, outputs=None)
54
- stop_button.click(on_stop_click, inputs=None, outputs=None)
55
 
56
  with gr.Row():
57
  output = [gr.Image(label=m, min_width=250, height=250, elem_id="custom_image") for m in default_models]
@@ -74,7 +69,7 @@ custom_css = """
74
  }
75
  body {
76
  background-color: var(--body-background-fill) !important;
77
- color: #c5c6c7;
78
  margin: 0;
79
  padding: 0;
80
  font-family: Arial, sans-serif;
@@ -223,4 +218,4 @@ with gr.Blocks(css=custom_css) as demo:
223
  make_me()
224
 
225
  demo.queue(concurrency_count=100)
226
- demo.launch()
 
2
  from random import randint
3
  from all_models import models
4
 
5
+ def load_fn(models):
 
6
  global models_load
7
+ models_load = {}
8
  for model in models:
9
+ if model not in models_load.keys():
10
+ try:
11
+ m = gr.load(f'models/{model}')
12
+ except Exception as error:
13
+ m = gr.Interface(lambda txt: None, ['text'], ['image'])
14
+ models_load.update({model: m})
15
 
16
+ load_fn(models)
17
 
18
  num_models = len(models)
19
  default_models = models[:num_models]
 
28
  def gen_fn(model_str, prompt):
29
  if model_str == 'NA':
30
  return None
31
+ noise = str(randint(0, 9999999))
32
+ return models_load[model_str](f'{prompt} {noise}')
33
 
34
  def make_me():
35
  with gr.Row():
36
+ with gr.Column(scale=1):
37
+ txt_input = gr.Textbox(label='Your prompt:', lines=3, container=False, elem_id="custom_textbox", placeholder="Prompt")
38
+ with gr.Row():
39
+ gen_button = gr.Button('Generate images', elem_id="custom_gen_button")
40
+ stop_button = gr.Button('Stop', variant='secondary', interactive=False, elem_id="custom_stop_button")
41
+
42
+ def on_generate_click():
43
+ return gr.Button('Generate images', elem_id="custom_gen_button"), gr.Button('Stop', variant='secondary', interactive=True, elem_id="custom_stop_button")
44
+
45
+ def on_stop_click():
46
+ return gr.Button('Generate images', elem_id="custom_gen_button"), gr.Button('Stop', variant='secondary', interactive=False, elem_id="custom_stop_button")
47
+
48
+ gen_button.click(on_generate_click, inputs=None, outputs=[gen_button, stop_button])
49
+ stop_button.click(on_stop_click, inputs=None, outputs=[gen_button, stop_button])
 
 
 
 
 
 
50
 
51
  with gr.Row():
52
  output = [gr.Image(label=m, min_width=250, height=250, elem_id="custom_image") for m in default_models]
 
69
  }
70
  body {
71
  background-color: var(--body-background-fill) !important;
72
+ color: #2d3d4f;
73
  margin: 0;
74
  padding: 0;
75
  font-family: Arial, sans-serif;
 
218
  make_me()
219
 
220
  demo.queue(concurrency_count=100)
221
+ demo.launch()