LeeveWasTaken commited on
Commit
27170c1
1 Parent(s): cfb78cb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -32
app.py CHANGED
@@ -2,12 +2,10 @@ 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 = {}
10
-
11
  for model in models:
12
  if model not in models_load.keys():
13
  try:
@@ -16,38 +14,36 @@ 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 = 6
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)
 
 
 
48
  gen_button = gr.Button('Generate up to 6 images in up to 1 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)
 
51
  gr.HTML(
52
  """
53
  <div style="text-align: center; max-width: 1200px; margin: 0 auto;">
@@ -60,25 +56,28 @@ with gr.Blocks() as demo:
60
  </div>
61
  """
62
  )
 
63
  with gr.Row():
64
- output = [gr.Image(label = m, min_width=480) for m in default_models]
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 best available!', value = default_models, multiselect = True, max_choices = num_models, interactive = True, filterable = False)
72
  model_choice.change(update_imgbox, model_choice, output)
73
  model_choice.change(extend_choices, model_choice, current_models)
 
74
  with gr.Row():
75
  gr.HTML(
76
- """
77
- <div class="footer">
78
- <p>Based on the <a href="https://huggingface.co/spaces/derwahnsinn/TestGen">TestGen</a> Space by derwahnsinn, the <a href="https://huggingface.co/spaces/RdnUser77/SpacIO_v1">SpacIO</a> Space by RdnUser77 and Omnibus's Maximum Multiplier!
79
- </p>
80
- """
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 = {}
8
+
9
  for model in models:
10
  if model not in models_load.keys():
11
  try:
 
14
  m = gr.Interface(lambda txt: None, ['text'], ['image'])
15
  models_load.update({model: m})
16
 
 
17
  load_fn(models)
18
 
 
19
  num_models = 6
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=None, image_style="Default"):
 
30
  if model_str == 'NA':
31
  return None
32
+ modified_prompt = f"{prompt}, {image_style}"
33
+ if negative_prompt:
34
+ modified_prompt += f", not {negative_prompt}"
35
+ return models_load[model_str](modified_prompt)
36
 
37
  with gr.Blocks() as demo:
38
+ with gr.Tab('The Dream'):
39
+ txt_input = gr.Textbox(label='Your prompt:', lines=4)
40
+ neg_prompt = gr.Textbox(label='Negative prompt (Optional):', placeholder='Enter undesirable attributes here', lines=2)
41
+ image_style = gr.Dropdown(label='Select Style', choices=["Default", "Cinematic", "Digital Art", "Portrait"], value="Default")
42
+
43
  gen_button = gr.Button('Generate up to 6 images in up to 1 minutes total')
44
+ stop_button = gr.Button('Stop', variant='secondary', interactive=False)
45
+
46
+ gen_button.click(lambda s: gr.update(interactive=True), None, stop_button)
47
  gr.HTML(
48
  """
49
  <div style="text-align: center; max-width: 1200px; margin: 0 auto;">
 
56
  </div>
57
  """
58
  )
59
+
60
  with gr.Row():
61
+ output = [gr.Image(label=m, min_width=480) for m in default_models]
62
+ current_models = [gr.Textbox(m, visible=False) for m in default_models]
63
+
64
  for m, o in zip(current_models, output):
65
+ gen_event = gen_button.click(gen_fn, [m, txt_input, neg_prompt, image_style], o)
66
+ stop_button.click(lambda s: gr.update(interactive=False), None, stop_button, cancels=[gen_event])
67
+
68
  with gr.Accordion('Model selection'):
69
+ model_choice = gr.CheckboxGroup(models, label=f'Choose up to {num_models} different models from the best available!', value=default_models, multiselect=True, max_choices=num_models, interactive=True, filterable=False)
70
  model_choice.change(update_imgbox, model_choice, output)
71
  model_choice.change(extend_choices, model_choice, current_models)
72
+
73
  with gr.Row():
74
  gr.HTML(
75
+ """
76
+ <div class="footer">
77
+ <p>Based on the <a href="https://huggingface.co/spaces/derwahnsinn/TestGen">TestGen</a> Space by derwahnsinn, the <a href="https://huggingface.co/spaces/RdnUser77/SpacIO_v1">SpacIO</a> Space by RdnUser77 and Omnibus's Maximum Multiplier!
78
+ </p>
79
+ """
80
+ )
81
+
82
+ demo.queue(concurrency_count=200)
83
  demo.launch()