phenomenon1981 commited on
Commit
89049aa
1 Parent(s): 83cb010

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -67
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-diffusion-1.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 queue_length_counter
39
  prompt_with_noise = add_random_noise(inputs, noise_level)
40
- if queue_length_counter >= 15:
41
- if not queue.empty():
42
- queue.queue.clear()
43
- queue_length_counter = 0
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 queue_length_counter
50
  prompt_with_noise = add_random_noise(inputs, noise_level)
51
- if queue_length_counter >= 15:
52
- if not queue.empty():
53
- queue.queue.clear()
54
- queue_length_counter = 0
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 queue_length_counter
61
  prompt_with_noise = add_random_noise(inputs, noise_level)
62
- if queue_length_counter >= 15:
63
- if not queue.empty():
64
- queue.queue.clear()
65
- queue_length_counter = 0
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 queue_length_counter
72
  prompt_with_noise = add_random_noise(inputs, noise_level)
73
- if queue_length_counter >= 15:
74
- if not queue.empty():
75
- queue.queue.clear()
76
- queue_length_counter = 0
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 queue_length_counter
83
  prompt_with_noise = add_random_noise(inputs, noise_level)
84
- if queue_length_counter >= 15:
85
- if not queue.empty():
86
- queue.queue.clear()
87
- queue_length_counter = 0
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 queue_length_counter
94
  prompt_with_noise = add_random_noise(inputs, noise_level)
95
- if queue_length_counter >= 15:
96
- if not queue.empty():
97
- queue.queue.clear()
98
- queue_length_counter = 0
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 queue_length_counter
105
  prompt_with_noise = add_random_noise(inputs, noise_level)
106
- if queue_length_counter >= 15:
107
- if not queue.empty():
108
- queue.queue.clear()
109
- queue_length_counter = 0
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 queue_length_counter
116
  prompt_with_noise = add_random_noise(inputs, noise_level)
117
- if queue_length_counter >= 15:
118
- if not queue.empty():
119
- queue.queue.clear()
120
- queue_length_counter = 0
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 queue_length_counter
129
- if queue_length_counter >= 15:
130
- if not queue.empty():
131
- queue.queue.clear()
132
- queue_length_counter = 0
133
- output = text_gen(prompt_text)
134
- queue_length_counter += 1
135
  return output
136
 
137
 
 
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-diffusion-1.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