Yntec commited on
Commit
cc411a4
โ€ข
1 Parent(s): bb51f97

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +180 -117
app.py CHANGED
@@ -1,36 +1,119 @@
1
  import gradio as gr
2
- import os
3
  import sys
4
  from pathlib import Path
5
-
6
- models = [
7
- "Yntec/OpenLexica",
8
- "Yntec/MapleSyrup",
9
- ]
10
- current_model = models[0]
11
 
12
- text_gen1=gr.Interface.load("spaces/Omnibus/MagicPrompt-Stable-Diffusion_link")
 
 
 
 
 
 
13
 
14
- models2=[
15
- gr.Interface.load(f"models/{models[0]}",live=True,preprocess=False),
16
- gr.Interface.load(f"models/{models[1]}",live=True,preprocess=False),
17
- ]
 
18
 
19
-
20
- def text_it1(inputs,text_gen1=text_gen1):
21
- go_t1=text_gen1(inputs)
22
- return(go_t1)
23
 
24
- def set_model(current_model):
25
- current_model = models[current_model]
26
- return gr.update(label=(f"{current_model}"))
27
 
28
 
29
- def send_it1(inputs, model_choice):
30
- proc1=models2[model_choice]
31
- output1=proc1(inputs)
32
- return(output1)
33
- css=""""""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
 
35
 
36
  with gr.Blocks(css='style.css') as demo:
@@ -48,107 +131,87 @@ with gr.Blocks(css='style.css') as demo:
48
  }
49
  </style>
50
  <body>
51
- <div class="center"><h1>ToyWorldXL 401</h1>
52
  </div>
53
  </body>
54
  </div>
55
  <p style="margin-bottom: 10px; color: #ffffff;">
56
  PlaceHolder
57
- </p>
 
58
  <p style="margin-bottom: 10px; color: #ffaa66; font-size: 98%">
59
  โค๏ธ Press the Like Button if you enjoy my space! โค๏ธ</a>
60
  </p>
61
  </div>
62
  """
63
  )
64
- with gr.Blocks(css=css) as myface:
65
- gr.HTML()
66
- with gr.Row():
67
- with gr.Tab("Title"):
68
- gr.HTML(""" <title>Minimum Multiplier</title><div style="text-align: center; max-width: 1500px; margin: 0 auto;">
69
- <h1>Fill the Textbox at the top and click Generate Image</h1>
70
- <br><h4>The first time you load a model it takes 200 seconds</h4>
71
- <br><h4>But after it loads each image takes 20 seconds to generate!</h4>
72
-
73
- """)
74
-
75
- with gr.Tab("Description"):
76
- gr.HTML("""<div style="text-align:center;">
77
- <h4>As many Text-to-Image Models as I can fit here</h4><br>
78
- <h4>Suggest more up in the "Community" button</h4>
79
-
80
- </div>""")
81
-
82
- with gr.Tab("Tools"):
83
- with gr.Tab("View"):
84
- with gr.Row():
85
- with gr.Column(style="width=50%, height=70%"):
86
- gr.Pil(label="Crop")
87
- with gr.Column(style="width=50%, height=70%"):
88
- gr.Pil(label="Crop")
89
-
90
-
91
- with gr.Tab("Draw"):
92
- with gr.Column(style="width=50%, height=70%"):
93
- gr.Pil(label="Crop")
94
- with gr.Column(style="width=50%, height=70%"):
95
- gr.Pil(label="Draw")
96
-
97
-
98
- gr.ImagePaint(label="Draw")
99
-
100
- with gr.Tab("Text"):
101
- with gr.Row():
102
-
103
- with gr.Column(scale=50):
104
- gr.Textbox(label="", lines=8, interactive=True)
105
-
106
-
107
- with gr.Column(scale=50):
108
- gr.Textbox(label="", lines=8, interactive=True)
109
-
110
- with gr.Tab("Color Picker"):
111
- with gr.Row():
112
-
113
- with gr.Column(scale=50):
114
- gr.ColorPicker(label="Color", interactive=True)
115
-
116
-
117
- with gr.Column(scale=50):
118
- gr.ImagePaint(label="Draw", interactive=True)
119
- with gr.Row():
120
- with gr.Column(scale=100):
121
- magic1=gr.Textbox(lines=4)
122
- gr.HTML("""<style> .gr-button {
123
- color: white !important;
124
- border-color: #000000 !important;
125
- background: #006699 !important;
126
- }</style>""")
127
- run=gr.Button("Generate Image")
128
- with gr.Row():
129
- with gr.Column(scale=100):
130
- #Model selection dropdown
131
- model_name1 = gr.Dropdown(label="Select Model", choices=[m for m in models], type="index", value=current_model, interactive=True)
132
- with gr.Row():
133
- with gr.Column(style="width=800px"):
134
- output1=gr.Image(label=(f"{current_model}"))
135
-
136
-
137
- with gr.Row():
138
- with gr.Column(scale=50):
139
- input_text=gr.Textbox(label="Use this box to extend an idea automagically, by typing some words and clicking Extend Idea",lines=2)
140
- use_short=gr.Button("Use Short Prompt")
141
- see_prompts=gr.Button("Extend Idea")
142
- def short_prompt(inputs):
143
- return(inputs)
144
-
145
- model_name1.change(set_model,inputs=model_name1,outputs=[output1])
146
-
147
- run.click(send_it1, inputs=[magic1, model_name1], outputs=[output1])
148
-
149
- use_short.click(short_prompt,inputs=[input_text],outputs=magic1)
150
-
151
- see_prompts.click(text_it1,inputs=[input_text],outputs=magic1)
152
-
153
- myface.queue(concurrency_count=200)
154
- myface.launch(inline=True, show_api=False, max_threads=400)
 
1
  import gradio as gr
2
+ import os
3
  import sys
4
  from pathlib import Path
5
+ import random
6
+ import string
7
+ import time
8
+ from queue import Queue
9
+ from threading import Thread
10
+ import emoji
11
 
12
+ text_gen=gr.Interface.load("spaces/phenomenon1981/MagicPrompt-Stable-Diffusion")
13
+ def get_prompts(prompt_text):
14
+ if prompt_text:
15
+ return text_gen(prompt_text + " Dream")
16
+ else:
17
+ return text_gen("")
18
+ proc1=gr.Interface.load("models/Yntec/DreamAnything")
19
 
20
+ def restart_script_periodically():
21
+ while True:
22
+ random_time = random.randint(5400, 6000)
23
+ time.sleep(random_time)
24
+ os.execl(sys.executable, sys.executable, *sys.argv)
25
 
 
 
 
 
26
 
27
+ restart_thread = Thread(target=restart_script_periodically, daemon=True)
28
+ restart_thread.start()
 
29
 
30
 
31
+ queue = Queue()
32
+ queue_threshold = 100
33
+
34
+ #Don't add noise to the first picture no matter what (the point of noise is to get varied outputs, the first one doesn't need to vary about anything)
35
+ def noadd_random_noise(prompt, noise_level=0.00):
36
+ if noise_level == 0:
37
+ noise_level = 0.00
38
+ percentage_noise = noise_level * 5
39
+ num_noise_chars = int(len(prompt) * (percentage_noise/100))
40
+ noise_indices = random.sample(range(len(prompt)), num_noise_chars)
41
+ prompt_list = list(prompt)
42
+ noise_chars = list(string.ascii_letters + string.punctuation + '' + string.digits)
43
+ noise_chars.extend([''])
44
+ for index in noise_indices:
45
+ prompt_list[index] = random.choice(noise_chars)
46
+ return "".join(prompt_list)
47
+
48
+ #normal behavior
49
+ def add_random_noise(prompt, noise_level=0.00):
50
+ if noise_level == 0:
51
+ noise_level = 0.00
52
+ percentage_noise = noise_level * 5
53
+ num_noise_chars = int(len(prompt) * (percentage_noise/100))
54
+ noise_indices = random.sample(range(len(prompt)), num_noise_chars)
55
+ prompt_list = list(prompt)
56
+ noise_chars = list(string.ascii_letters + string.punctuation + ' ' + string.digits)
57
+ noise_chars.extend(['๐Ÿ˜', 'beautiful', '๐Ÿ˜‚', '๐Ÿค”', '๐Ÿ˜Š', '๐Ÿค—', '๐Ÿ˜ญ', '๐Ÿ™„', 'pretty', '๐Ÿคฏ', '๐Ÿคซ', '๐Ÿฅด', 'sitting', '๐Ÿคฉ', '๐Ÿฅณ', '๐Ÿ˜”', '๐Ÿ˜ฉ', '๐Ÿคช', '๐Ÿ˜‡', 'retro', '๐Ÿ˜ˆ', '๐Ÿ‘น', 'masterpiece', '๐Ÿค–', '๐Ÿ‘ฝ', 'high quality', '๐ŸŽƒ', '๐ŸŽ…', '๐ŸŽ„', '๐ŸŽ', '๐ŸŽ‚', '๐ŸŽ‰', '๐ŸŽˆ', '๐ŸŽŠ', '๐ŸŽฎ', 'โค๏ธ', '๐Ÿ’”', '๐Ÿ’•', '๐Ÿ’–', '๐Ÿ’—', '๐Ÿถ', '๐Ÿฑ', 'visible', '๐Ÿน', '๐ŸฆŠ', '๐Ÿป', '๐Ÿจ', '๐Ÿฏ', '๐Ÿฆ', '๐Ÿ˜', '๐Ÿ”ฅ', '๐ŸŒง๏ธ', '๐ŸŒž', '๐ŸŒˆ', '๐Ÿ’ฅ', '๐ŸŒด', '๐ŸŒŠ', '๐ŸŒบ', '๐ŸŒป', '๐ŸŒธ', '๐ŸŽจ', '๐ŸŒ…', '๐ŸŒŒ', 'โ˜๏ธ', 'โ›ˆ๏ธ', 'โ„๏ธ', 'โ˜€๏ธ', '๐ŸŒค๏ธ', 'โ›…๏ธ', '๐ŸŒฅ๏ธ', '๐ŸŒฆ๏ธ', '๐ŸŒง๏ธ', '๐ŸŒฉ๏ธ', '๐ŸŒจ๏ธ', '๐ŸŒซ๏ธ', 'โ˜”๏ธ', '๐ŸŒฌ๏ธ', '๐Ÿ’จ', '๐ŸŒช๏ธ', 'cute', 'kawaii', 'little'])
58
+ for index in noise_indices:
59
+ prompt_list[index] = random.choice(noise_chars)
60
+ return "".join(prompt_list)
61
+
62
+ def send_it1(inputs, noise_level, proc1=proc1):
63
+ prompt_with_noise = noadd_random_noise(inputs, noise_level)
64
+ while queue.qsize() >= queue_threshold:
65
+ time.sleep(2)
66
+ queue.put(prompt_with_noise)
67
+ output1 = proc1(prompt_with_noise)
68
+ return output1
69
+
70
+ def send_it2(inputs, noise_level, proc1=proc1):
71
+ prompt_with_noise = add_random_noise(inputs, noise_level)
72
+ while queue.qsize() >= queue_threshold:
73
+ time.sleep(2)
74
+ queue.put(prompt_with_noise)
75
+ output2 = proc1(prompt_with_noise)
76
+ return output2
77
+
78
+ def send_itX(inputs, noise_level, proc1=proc1):
79
+ prompt_with_noise = add_random_noise(inputs, noise_level)
80
+ while queue.qsize() >= queue_threshold:
81
+ time.sleep(2)
82
+ queue.put(prompt_with_noise)
83
+ outputX = proc1(prompt_with_noise)
84
+ return outputX
85
+
86
+ def send_it3(inputs, noise_level, proc1=proc1):
87
+ prompt_with_noise = add_random_noise(inputs, noise_level)
88
+ while queue.qsize() >= queue_threshold:
89
+ time.sleep(2)
90
+ queue.put(prompt_with_noise)
91
+ output3 = proc1(prompt_with_noise)
92
+ return output3
93
+
94
+ def send_it4(inputs, noise_level, proc1=proc1):
95
+ prompt_with_noise = add_random_noise(inputs, noise_level)
96
+ while queue.qsize() >= queue_threshold:
97
+ time.sleep(2)
98
+ queue.put(prompt_with_noise)
99
+ output4 = proc1(prompt_with_noise)
100
+ return output4
101
+
102
+ def send_it5(inputs, noise_level, proc1=proc1):
103
+ prompt_with_noise = add_random_noise(inputs, noise_level)
104
+ while queue.qsize() >= queue_threshold:
105
+ time.sleep(2)
106
+ queue.put(prompt_with_noise)
107
+ output5 = proc1(prompt_with_noise)
108
+ return output5
109
+
110
+ #def send_it7(inputs, noise_level, proc1=proc1):
111
+ #prompt_with_noise = add_random_noise(inputs, noise_level)
112
+ #while queue.qsize() >= queue_threshold:
113
+ # time.sleep(2)
114
+ #queue.put(prompt_with_noise)
115
+ #output5 = proc1(prompt_with_noise)
116
+ #return output0
117
 
118
 
119
  with gr.Blocks(css='style.css') as demo:
 
131
  }
132
  </style>
133
  <body>
134
+ <div class="center"><h1>ToyWorld XL 401</h1>
135
  </div>
136
  </body>
137
  </div>
138
  <p style="margin-bottom: 10px; color: #ffffff;">
139
  PlaceHolder
140
+ <a href="https://twitter.com/DavidJohnstonxx/">original space created by Phenomenon1981</a>.
141
+ </p>
142
  <p style="margin-bottom: 10px; color: #ffaa66; font-size: 98%">
143
  โค๏ธ Press the Like Button if you enjoy my space! โค๏ธ</a>
144
  </p>
145
  </div>
146
  """
147
  )
148
+ with gr.Column(elem_id="col-container"):
149
+ with gr.Row(variant="compact"):
150
+ input_text = gr.Textbox(
151
+ label="Short Prompt",
152
+ show_label=False,
153
+ max_lines=2,
154
+ placeholder="Enter a basic idea and click 'Magic Prompt'. Got no ideas? No problem, Simply just hit the magic button!",
155
+ ).style(
156
+ container=False,min_width=1200
157
+ )
158
+ see_prompts = gr.Button("โœจ Magic Prompt โœจ").style(full_width=False)
159
+
160
+
161
+ with gr.Row(variant="compact"):
162
+ prompt = gr.Textbox(
163
+ label="Enter your prompt",
164
+ show_label=False,
165
+ max_lines=2,
166
+ placeholder="Full Prompt",
167
+ ).style(
168
+ container=False,
169
+ )
170
+ run = gr.Button("Generate Images").style(full_width=False)
171
+
172
+ with gr.Row():
173
+ with gr.Row():
174
+ #Now that the first box generates a picture with noise=0 having the default at 0 makes no sense as it'd generate the same image 6 times.
175
+ noise_level = gr.Slider(minimum=0.2, maximum=3, step=0.1, label="Noise Level (0.1 or less was generating the same pic 6 times! ๐Ÿคฃ)")
176
+ with gr.Row():
177
+ with gr.Row():
178
+ output1=gr.Image(label="DreamAnything",show_label=False,min_width=640)
179
+ output2=gr.Image(label="DreamAnything",show_label=False,min_width=640)
180
+ with gr.Row():
181
+ with gr.Row():
182
+ output3=gr.Image(label="DreamAnything",show_label=False,min_width=640)
183
+ output4=gr.Image(label="DreamAnything",show_label=False,min_width=640)
184
+ with gr.Row():
185
+ with gr.Row():
186
+ output5=gr.Image(label="DreamAnything",show_label=False,min_width=640)
187
+ outputX=gr.Image(label="DreamAnything",show_label=False,min_width=640)
188
+ #with gr.Row():
189
+ #with gr.Row():
190
+ #output0=gr.Image(label="DreamAnything",show_label=False,min_width=640)
191
+
192
+ see_prompts.click(get_prompts, inputs=[input_text], outputs=[prompt], queue=False)
193
+ run.click(send_it1, inputs=[prompt, noise_level], outputs=[output1])
194
+ #run.click(send_it7, inputs=[prompt, noise_level], outputs=[output0])
195
+ run.click(send_it2, inputs=[prompt, noise_level], outputs=[output2])
196
+ run.click(send_it3, inputs=[prompt, noise_level], outputs=[output3])
197
+ run.click(send_it4, inputs=[prompt, noise_level], outputs=[output4])
198
+ run.click(send_it5, inputs=[prompt, noise_level], outputs=[output5])
199
+ run.click(send_itX, inputs=[prompt, noise_level], outputs=[outputX])
200
+
201
+
202
+ with gr.Row():
203
+ gr.HTML(
204
+ """
205
+ <div class="footer">
206
+ <p> Demo for <a href="https://huggingface.co/Yntec/DreamAnything">DreamAnything</a> Stable Diffusion model
207
+ </p>
208
+ </div>
209
+ <div class="acknowledgments" style="font-size: 115%; color: #ffffff;">
210
+ <p> Unleash your creative side and generate mesmerizing images with just a few clicks! Enter a spark of inspiration in the "Basic Idea" text box and click the "Magic Prompt" button to elevate it to a polished masterpiece. Make any final tweaks in the "Full Prompt" box and hit the "Generate Images" button to watch your vision come to life. Experiment with the "Noise Level" for a diverse range of outputs, from similar to wildly unique. Let the fun begin!
211
+ </p>
212
+ </div>
213
+ """
214
+ )
215
+
216
+ demo.launch(enable_queue=True, inline=True)
217
+ block.queue(concurrency_count=100)