Spaces:
Runtime error
Runtime error
Commit
·
50f9d19
1
Parent(s):
92d8bdb
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,14 +1,16 @@
|
|
| 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 |
-
queue = Queue()
|
| 10 |
from threading import Thread
|
| 11 |
|
|
|
|
|
|
|
|
|
|
| 12 |
text_gen=gr.Interface.load("spaces/Omnibus/MagicPrompt-Stable-Diffusion")
|
| 13 |
proc1=gr.Interface.load("models/dreamlike-art/dreamlike-photoreal-2.0")
|
| 14 |
|
|
@@ -32,106 +34,86 @@ def add_random_noise(prompt, noise_level=0.07):
|
|
| 32 |
prompt_list[index] = random.choice(string.ascii_letters + string.punctuation)
|
| 33 |
return "".join(prompt_list)
|
| 34 |
|
| 35 |
-
queue_length_counter = 0
|
| 36 |
|
| 37 |
def send_it1(inputs, noise_level, proc1=proc1):
|
| 38 |
-
global
|
| 39 |
prompt_with_noise = add_random_noise(inputs, noise_level)
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
output1 = proc1(prompt_with_noise)
|
| 45 |
-
queue_length_counter += 1
|
| 46 |
return output1
|
| 47 |
|
| 48 |
def send_it2(inputs, noise_level, proc1=proc1):
|
| 49 |
-
global
|
| 50 |
prompt_with_noise = add_random_noise(inputs, noise_level)
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
output2 = proc1(prompt_with_noise)
|
| 56 |
-
queue_length_counter += 1
|
| 57 |
return output2
|
| 58 |
|
| 59 |
def send_it3(inputs, noise_level, proc1=proc1):
|
| 60 |
-
global
|
| 61 |
prompt_with_noise = add_random_noise(inputs, noise_level)
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
output3 = proc1(prompt_with_noise)
|
| 67 |
-
queue_length_counter += 1
|
| 68 |
return output3
|
| 69 |
|
| 70 |
def send_it4(inputs, noise_level, proc1=proc1):
|
| 71 |
-
global
|
| 72 |
prompt_with_noise = add_random_noise(inputs, noise_level)
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
output4 = proc1(prompt_with_noise)
|
| 78 |
-
queue_length_counter += 1
|
| 79 |
return output4
|
| 80 |
|
| 81 |
def send_it5(inputs, noise_level, proc1=proc1):
|
| 82 |
-
global
|
| 83 |
prompt_with_noise = add_random_noise(inputs, noise_level)
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
output5 = proc1(prompt_with_noise)
|
| 89 |
-
queue_length_counter += 1
|
| 90 |
return output5
|
| 91 |
|
| 92 |
def send_it6(inputs, noise_level, proc1=proc1):
|
| 93 |
-
global
|
| 94 |
prompt_with_noise = add_random_noise(inputs, noise_level)
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
output6 = proc1(prompt_with_noise)
|
| 100 |
-
queue_length_counter += 1
|
| 101 |
return output6
|
| 102 |
|
| 103 |
def send_it7(inputs, noise_level, proc1=proc1):
|
| 104 |
-
global
|
| 105 |
prompt_with_noise = add_random_noise(inputs, noise_level)
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
output7 = proc1(prompt_with_noise)
|
| 111 |
-
queue_length_counter += 1
|
| 112 |
return output7
|
| 113 |
|
| 114 |
def send_it8(inputs, noise_level, proc1=proc1):
|
| 115 |
-
global
|
| 116 |
prompt_with_noise = add_random_noise(inputs, noise_level)
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
output8 = proc1(prompt_with_noise)
|
| 122 |
-
queue_length_counter += 1
|
| 123 |
return output8
|
| 124 |
|
| 125 |
|
| 126 |
-
|
| 127 |
def get_prompts(prompt_text):
|
| 128 |
-
global
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
output = text_gen(prompt_text)
|
| 134 |
-
queue_length_counter += 1
|
| 135 |
return output
|
| 136 |
|
| 137 |
|
|
@@ -149,17 +131,17 @@ with gr.Blocks() as myface:
|
|
| 149 |
with gr.Row():
|
| 150 |
like_message = gr.Button("❤️ Press the Like Button if you enjoy my space! ❤️")
|
| 151 |
with gr.Row():
|
| 152 |
-
output1=gr.Image(label="Dreamlike
|
| 153 |
-
output2=gr.Image(label="Dreamlike
|
| 154 |
with gr.Row():
|
| 155 |
-
output3=gr.Image(label="Dreamlike
|
| 156 |
-
output4=gr.Image(label="Dreamlike
|
| 157 |
with gr.Row():
|
| 158 |
-
output5=gr.Image(label="Dreamlike
|
| 159 |
-
output6=gr.Image(label="Dreamlike
|
| 160 |
with gr.Row():
|
| 161 |
-
output7=gr.Image(label="Dreamlike
|
| 162 |
-
output8=gr.Image(label="Dreamlike
|
| 163 |
|
| 164 |
|
| 165 |
run.click(send_it1, inputs=[prompt, noise_level], outputs=[output1])
|
|
@@ -174,8 +156,8 @@ with gr.Blocks() as myface:
|
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
-
myface.queue(concurrency_count=8)
|
| 178 |
-
myface.launch(enable_queue=True, inline=True)
|
| 179 |
|
| 180 |
def queue_monitor():
|
| 181 |
while True:
|
|
|
|
| 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 |
|
| 11 |
+
queue = Queue()
|
| 12 |
+
queue_threshold = 15
|
| 13 |
+
|
| 14 |
text_gen=gr.Interface.load("spaces/Omnibus/MagicPrompt-Stable-Diffusion")
|
| 15 |
proc1=gr.Interface.load("models/dreamlike-art/dreamlike-photoreal-2.0")
|
| 16 |
|
|
|
|
| 34 |
prompt_list[index] = random.choice(string.ascii_letters + string.punctuation)
|
| 35 |
return "".join(prompt_list)
|
| 36 |
|
|
|
|
| 37 |
|
| 38 |
def send_it1(inputs, noise_level, proc1=proc1):
|
| 39 |
+
global queue
|
| 40 |
prompt_with_noise = add_random_noise(inputs, noise_level)
|
| 41 |
+
queue.put(prompt_with_noise)
|
| 42 |
+
while queue.qsize() > queue_threshold:
|
| 43 |
+
time.sleep(1)
|
| 44 |
+
output1 = proc1(queue.get())
|
|
|
|
|
|
|
| 45 |
return output1
|
| 46 |
|
| 47 |
def send_it2(inputs, noise_level, proc1=proc1):
|
| 48 |
+
global queue
|
| 49 |
prompt_with_noise = add_random_noise(inputs, noise_level)
|
| 50 |
+
queue.put(prompt_with_noise)
|
| 51 |
+
while queue.qsize() > queue_threshold:
|
| 52 |
+
time.sleep(1)
|
| 53 |
+
output2 = proc1(queue.get())
|
|
|
|
|
|
|
| 54 |
return output2
|
| 55 |
|
| 56 |
def send_it3(inputs, noise_level, proc1=proc1):
|
| 57 |
+
global queue
|
| 58 |
prompt_with_noise = add_random_noise(inputs, noise_level)
|
| 59 |
+
queue.put(prompt_with_noise)
|
| 60 |
+
while queue.qsize() > queue_threshold:
|
| 61 |
+
time.sleep(1)
|
| 62 |
+
output3 = proc1(queue.get())
|
|
|
|
|
|
|
| 63 |
return output3
|
| 64 |
|
| 65 |
def send_it4(inputs, noise_level, proc1=proc1):
|
| 66 |
+
global queue
|
| 67 |
prompt_with_noise = add_random_noise(inputs, noise_level)
|
| 68 |
+
queue.put(prompt_with_noise)
|
| 69 |
+
while queue.qsize() > queue_threshold:
|
| 70 |
+
time.sleep(1)
|
| 71 |
+
output4 = proc1(queue.get())
|
|
|
|
|
|
|
| 72 |
return output4
|
| 73 |
|
| 74 |
def send_it5(inputs, noise_level, proc1=proc1):
|
| 75 |
+
global queue
|
| 76 |
prompt_with_noise = add_random_noise(inputs, noise_level)
|
| 77 |
+
queue.put(prompt_with_noise)
|
| 78 |
+
while queue.qsize() > queue_threshold:
|
| 79 |
+
time.sleep(1)
|
| 80 |
+
output5 = proc1(queue.get())
|
|
|
|
|
|
|
| 81 |
return output5
|
| 82 |
|
| 83 |
def send_it6(inputs, noise_level, proc1=proc1):
|
| 84 |
+
global queue
|
| 85 |
prompt_with_noise = add_random_noise(inputs, noise_level)
|
| 86 |
+
queue.put(prompt_with_noise)
|
| 87 |
+
while queue.qsize() > queue_threshold:
|
| 88 |
+
time.sleep(1)
|
| 89 |
+
output6 = proc1(queue.get())
|
|
|
|
|
|
|
| 90 |
return output6
|
| 91 |
|
| 92 |
def send_it7(inputs, noise_level, proc1=proc1):
|
| 93 |
+
global queue
|
| 94 |
prompt_with_noise = add_random_noise(inputs, noise_level)
|
| 95 |
+
queue.put(prompt_with_noise)
|
| 96 |
+
while queue.qsize() > queue_threshold:
|
| 97 |
+
time.sleep(1)
|
| 98 |
+
output7 = proc1(queue.get())
|
|
|
|
|
|
|
| 99 |
return output7
|
| 100 |
|
| 101 |
def send_it8(inputs, noise_level, proc1=proc1):
|
| 102 |
+
global queue
|
| 103 |
prompt_with_noise = add_random_noise(inputs, noise_level)
|
| 104 |
+
queue.put(prompt_with_noise)
|
| 105 |
+
while queue.qsize() > queue_threshold:
|
| 106 |
+
time.sleep(1)
|
| 107 |
+
output8 = proc1(queue.get())
|
|
|
|
|
|
|
| 108 |
return output8
|
| 109 |
|
| 110 |
|
|
|
|
| 111 |
def get_prompts(prompt_text):
|
| 112 |
+
global queue
|
| 113 |
+
queue.put(prompt_text)
|
| 114 |
+
while queue.qsize() > queue_threshold:
|
| 115 |
+
time.sleep(1)
|
| 116 |
+
output = text_gen(queue.get())
|
|
|
|
|
|
|
| 117 |
return output
|
| 118 |
|
| 119 |
|
|
|
|
| 131 |
with gr.Row():
|
| 132 |
like_message = gr.Button("❤️ Press the Like Button if you enjoy my space! ❤️")
|
| 133 |
with gr.Row():
|
| 134 |
+
output1=gr.Image(label="Dreamlike-photoreal-2.0")
|
| 135 |
+
output2=gr.Image(label="Dreamlike-photoreal-2.0")
|
| 136 |
with gr.Row():
|
| 137 |
+
output3=gr.Image(label="Dreamlike-photoreal-2.0")
|
| 138 |
+
output4=gr.Image(label="Dreamlike-photoreal-2.0")
|
| 139 |
with gr.Row():
|
| 140 |
+
output5=gr.Image(label="Dreamlike-photoreal-2.0")
|
| 141 |
+
output6=gr.Image(label="Dreamlike-photoreal-2.0")
|
| 142 |
with gr.Row():
|
| 143 |
+
output7=gr.Image(label="Dreamlike-photoreal-2.0")
|
| 144 |
+
output8=gr.Image(label="Dreamlike-photoreal-2.0")
|
| 145 |
|
| 146 |
|
| 147 |
run.click(send_it1, inputs=[prompt, noise_level], outputs=[output1])
|
|
|
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
+
myface.queue(concurrency_count=8)
|
| 160 |
+
myface.launch(enable_queue=True, inline=True)
|
| 161 |
|
| 162 |
def queue_monitor():
|
| 163 |
while True:
|