jordonpeter01 commited on
Commit
0ec837d
·
verified ·
1 Parent(s): f1acb7b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -14
app.py CHANGED
@@ -2,8 +2,6 @@ import gradio as gr
2
  from random import randint
3
  from all_models import models
4
 
5
-
6
-
7
  def load_fn(models):
8
  global models_load
9
  models_load = {}
@@ -16,35 +14,28 @@ def load_fn(models):
16
  m = gr.Interface(lambda txt: None, ['text'], ['image'])
17
  models_load.update({model: m})
18
 
19
-
20
  load_fn(models)
21
 
22
-
23
  num_models = 150
24
  default_models = models[:num_models]
25
 
26
-
27
-
28
  def extend_choices(choices):
29
  return choices + (num_models - len(choices)) * ['NA']
30
 
31
-
32
  def update_imgbox(choices):
33
  choices_plus = extend_choices(choices)
34
  return [gr.Image(None, label = m, visible = (m != 'NA')) for m in choices_plus]
35
 
36
-
37
- def gen_fn(model_str, prompt):
38
  if model_str == 'NA':
39
  return None
40
  noise = str('') #str(randint(0, 99999999999))
41
- return models_load[model_str](f'{prompt} {noise}')
42
-
43
-
44
 
45
  with gr.Blocks() as demo:
46
  with gr.Tab('The Dream'):
47
  txt_input = gr.Textbox(label = 'Your prompt:', lines=4).style(container=False,min_width=1200)
 
48
  gen_button = gr.Button('Generate up to 150 images in up to 3 minutes total')
49
  stop_button = gr.Button('Stop', variant = 'secondary', interactive = False)
50
  gen_button.click(lambda s: gr.update(interactive = True), None, stop_button)
@@ -65,7 +56,7 @@ with gr.Blocks() as demo:
65
  current_models = [gr.Textbox(m, visible = False) for m in default_models]
66
 
67
  for m, o in zip(current_models, output):
68
- gen_event = gen_button.click(gen_fn, [m, txt_input], o)
69
  stop_button.click(lambda s: gr.update(interactive = False), None, stop_button, cancels = [gen_event])
70
  with gr.Accordion('Model selection'):
71
  model_choice = gr.CheckboxGroup(models, label = f'Choose up to {num_models} different models from the 755 available!', value = default_models, multiselect = True, max_choices = num_models, interactive = True, filterable = False)
@@ -81,4 +72,4 @@ with gr.Blocks() as demo:
81
  )
82
 
83
  demo.queue(concurrency_count = 200)
84
- 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 = {}
 
14
  m = gr.Interface(lambda txt: None, ['text'], ['image'])
15
  models_load.update({model: m})
16
 
 
17
  load_fn(models)
18
 
 
19
  num_models = 150
20
  default_models = models[:num_models]
21
 
 
 
22
  def extend_choices(choices):
23
  return choices + (num_models - len(choices)) * ['NA']
24
 
 
25
  def update_imgbox(choices):
26
  choices_plus = extend_choices(choices)
27
  return [gr.Image(None, label = m, visible = (m != 'NA')) for m in choices_plus]
28
 
29
+ def gen_fn(model_str, prompt, negative_prompt):
 
30
  if model_str == 'NA':
31
  return None
32
  noise = str('') #str(randint(0, 99999999999))
33
+ return models_loadmodel_str
 
 
34
 
35
  with gr.Blocks() as demo:
36
  with gr.Tab('The Dream'):
37
  txt_input = gr.Textbox(label = 'Your prompt:', lines=4).style(container=False,min_width=1200)
38
+ negative_txt_input = gr.Textbox(label = 'Your negative prompt:', lines=4).style(container=False,min_width=1200)
39
  gen_button = gr.Button('Generate up to 150 images in up to 3 minutes total')
40
  stop_button = gr.Button('Stop', variant = 'secondary', interactive = False)
41
  gen_button.click(lambda s: gr.update(interactive = True), None, stop_button)
 
56
  current_models = [gr.Textbox(m, visible = False) for m in default_models]
57
 
58
  for m, o in zip(current_models, output):
59
+ gen_event = gen_button.click(gen_fn, [m, txt_input, negative_txt_input], o)
60
  stop_button.click(lambda s: gr.update(interactive = False), None, stop_button, cancels = [gen_event])
61
  with gr.Accordion('Model selection'):
62
  model_choice = gr.CheckboxGroup(models, label = f'Choose up to {num_models} different models from the 755 available!', value = default_models, multiselect = True, max_choices = num_models, interactive = True, filterable = False)
 
72
  )
73
 
74
  demo.queue(concurrency_count = 200)
75
+ demo.launch()