TheMaisk commited on
Commit
3adba3d
1 Parent(s): bcb3264

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +123 -0
app.py ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
9
+ models_load = {}
10
+
11
+ for model in models:
12
+ if model not in models_load.keys():
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 = 1
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
+ def gen_fnsix(model_str, prompt):
44
+ if model_str == 'NA':
45
+ return None
46
+ noisesix = str(randint(1941, 2023)) #str(randint(0, 99999999999))
47
+ return models_load[model_str](f'{prompt} {noisesix}')
48
+ with gr.Blocks() as demo:
49
+ gr.HTML(
50
+ """
51
+ <div>
52
+ <p> <center><img src="https://einfachalex.net/wp-content/uploads/2024/02/696f61d7a31edd36aa11414db3ba2854.png" style="height:128px; width:482px; margin-top: -22px; margin-bottom: -44px;" span title="Free ai art image generator Printing Press"></center>
53
+ </p>
54
+ """
55
+ )
56
+ with gr.Tab('One Image'):
57
+ model_choice = gr.Dropdown(models, label = 'Choose a model from the 697 available!', value = models[0], filterable = False)
58
+ txt_input = gr.Textbox(label = 'Your prompt:')
59
+
60
+ max_imagesone = 1
61
+ num_imagesone = gr.Slider(1, max_imagesone, value = max_imagesone, step = 1, label = 'Nobody gets to see this label so I can put here whatever I want!', visible = False)
62
+
63
+ gen_button = gr.Button('Generate')
64
+ stop_button = gr.Button('Stop', variant = 'secondary', interactive = False)
65
+ gen_button.click(lambda s: gr.update(interactive = True), None, stop_button)
66
+
67
+ with gr.Row():
68
+ output = [gr.Image(label = '') for _ in range(max_imagesone)]
69
+
70
+ for i, o in enumerate(output):
71
+ img_in = gr.Number(i, visible = False)
72
+ num_imagesone.change(lambda i, n: gr.update(visible = (i < n)), [img_in, num_imagesone], o, show_progress = False)
73
+ gen_event = gen_button.click(lambda i, n, m, t: gen_fn(m, t) if (i < n) else None, [img_in, num_imagesone, model_choice, txt_input], o)
74
+ stop_button.click(lambda s: gr.update(interactive = False), None, stop_button, cancels = [gen_event])
75
+ with gr.Row():
76
+ gr.HTML(
77
+ """
78
+ <div class="footer">
79
+ <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, Omnibus's Maximum Multiplier, <a href="https://huggingface.co/spaces/Yntec/Diffusion60XX">Diffusion60XX</a> and <a href="https://huggingface.co/spaces/Yntec/ToyWorld">Toy World</a>!
80
+ </p>
81
+ """
82
+ )
83
+ with gr.Tab('Up To Six'):
84
+ model_choice2 = gr.Dropdown(models, label = 'Choose a model from the 697 available!', value = models[0], filterable = False)
85
+ txt_input2 = gr.Textbox(label = 'Your prompt:')
86
+
87
+ max_images = 6
88
+ num_images = gr.Slider(1, max_images, value = max_images, step = 1, label = 'Number of images (if you want less than 6 decrease them slowly until they match the boxes below)')
89
+
90
+ gen_button2 = gr.Button('Generate up to 6 images in up to 3 minutes total')
91
+ stop_button2 = gr.Button('Stop', variant = 'secondary', interactive = False)
92
+ gen_button2.click(lambda s: gr.update(interactive = True), None, stop_button2)
93
+ gr.HTML(
94
+ """
95
+ <div style="text-align: center; max-width: 1200px; margin: 0 auto;">
96
+ <div>
97
+ <body>
98
+ <div class="center"><p style="margin-bottom: 10px; color: #000000;">Scroll down to see more images (they generate in a random order).</p>
99
+ </div>
100
+ </body>
101
+ </div>
102
+ </div>
103
+ """
104
+ )
105
+ with gr.Column():
106
+ output2 = [gr.Image(label = '') for _ in range(max_images)]
107
+
108
+ for i, o in enumerate(output2):
109
+ img_i = gr.Number(i, visible = False)
110
+ num_images.change(lambda i, n: gr.update(visible = (i < n)), [img_i, num_images], o, show_progress = False)
111
+ gen_event2 = gen_button2.click(lambda i, n, m, t: gen_fnsix(m, t) if (i < n) else None, [img_i, num_images, model_choice2, txt_input2], o)
112
+ stop_button2.click(lambda s: gr.update(interactive = False), None, stop_button2, cancels = [gen_event2])
113
+ with gr.Row():
114
+ gr.HTML(
115
+ """
116
+ <div class="footer">
117
+ <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, Omnibus's Maximum Multiplier, <a href="https://huggingface.co/spaces/Yntec/Diffusion60XX">Diffusion60XX</a> and <a href="https://huggingface.co/spaces/Yntec/ToyWorld">Toy World</a>!
118
+ </p>
119
+ """
120
+ )
121
+
122
+ demo.queue(concurrency_count = 200)
123
+ demo.launch()