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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +67 -94
app.py CHANGED
@@ -1,15 +1,8 @@
1
  import gradio as gr
2
  from random import randint
3
  from all_models import models
4
- from gradio import Interface
5
 
6
- # Define Bootstrap CSS styles
7
- bootstrap_css = """
8
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-zCbKRCUGaJDkqO4aIfeHaHNVy2QWhv2P+nvf4jCF0S42kqR8YcOrHndjw6qplMFZrk" crossorigin="anonymous">
9
- """
10
 
11
- # Set global CSS using gr.Config
12
- gr.Config(css=[bootstrap_css])
13
 
14
  def load_fn(models):
15
  global models_load
@@ -20,92 +13,72 @@ def load_fn(models):
20
  try:
21
  m = gr.load(f'models/{model}')
22
  except Exception as error:
23
- m = Interface(lambda txt: None, ['text'], ['image'])
24
- models_load[model] = m
25
-
26
- load_fn(models)
27
-
28
- num_models = 150
29
- default_models = models[:num_models]
30
-
31
- def extend_choices(choices):
32
- return choices + (num_models - len(choices)) * ['NA']
33
-
34
- def update_imgbox(choices):
35
- choices_plus = extend_choices(choices)
36
- return [gr.Image(None, label=m, visible=(m != 'NA')) for m in choices_plus]
37
-
38
- def gen_fn(model_str, prompt):
39
- if model_str == 'NA':
40
- return None
41
- noise = str(randint(0, 99999999999))
42
- return models_load[model_str](f'{prompt} {noise}')
43
-
44
- with gr.Blocks() as demo:
45
- with gr.Tab('The Dream'):
46
- txt_input = gr.Textbox(label='Your prompt:', lines=4).style(
47
- 'text-align: left;',
48
- 'width: 100%;',
49
- 'margin-bottom: 20px;',
50
- 'font-size: 16px;'
51
- )
52
-
53
- gen_button = gr.Button(
54
- 'Generate up to 150 images in up to 3 minutes total',
55
- style='margin-bottom: 20px;'
56
- )
57
-
58
- stop_button = gr.Button(
59
- 'Stop',
60
- variant='danger',
61
- interactive=False,
62
- style='margin-bottom: 20px;'
63
- )
64
-
65
- gen_button.click(lambda s: gr.update(interactive=True), None, stop_button)
66
 
67
- gr.HTML(
68
- """
69
- <div style="text-align: left; max-width: 800px; margin: 0 auto;">
70
- <p style="margin-bottom: 10px; color: #333333;">Enter your prompt in the text box and click "Generate" to start generating images.</p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
  </div>
72
- """
73
- )
74
-
75
- with gr.Row():
76
- output = [gr.Image(label=m, min_width=250) for m in default_models]
77
- current_models = [gr.Textbox(m, visible=False) for m in default_models]
78
-
79
- for m, o in zip(current_models, output):
80
- gen_event = gen_button.click(gen_fn, [m, txt_input], o)
81
- stop_button.click(lambda s: gr.update(interactive=False), None, stop_button, cancels=[gen_event])
82
-
83
- with gr.Accordion('Model selection'):
84
- model_choice = gr.CheckboxGroup(
85
- models,
86
- label=f'Choose up to {num_models} different models out of {len(models)} available!',
87
- value=default_models,
88
- multiselect=True,
89
- max_choices=num_models,
90
- interactive=True,
91
- filterable=True,
92
- style='width: 100%;'
93
- )
94
-
95
- model_choice.change(update_imgbox, model_choice, output)
96
- model_choice.change(extend_choices, model_choice, current_models)
97
-
98
- with gr.Row():
99
- gr.HTML(
100
- """
101
- <div class="footer">
102
- <p style="font-size: 14px; color: #666666;">
103
- Based on the <a href="https://huggingface.co/spaces/derwahnsinn/TestGen">TestGen</a> Space by derwahnsinn,
104
- the <a href="https://huggingface.co/spaces/RdnUser77/SpacIO_v1">SpacIO</a> Space by RdnUser77 and Omnibus's Maximum Multiplier!
105
- </p>
106
- </div>
107
- """
108
- )
109
-
110
- demo.queue(concurrency_count=200)
111
- demo.launch()
 
1
  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
 
13
  try:
14
  m = gr.load(f'models/{model}')
15
  except Exception as error:
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)
51
+ gr.HTML(
52
+ """
53
+ <div style="text-align: center; max-width: 1200px; margin: 0 auto;">
54
+ <div>
55
+ <body>
56
+ <div class="center"><p style="margin-bottom: 10px; color: #000000;">Scroll down to see more images and select models.</p>
57
  </div>
58
+ </body>
59
+ </div>
60
+ </div>
61
+ """
62
+ )
63
+ with gr.Row():
64
+ output = [gr.Image(label = m, min_width=768) 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 755 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()