phenomenon1981 commited on
Commit
9cb1e92
1 Parent(s): 7cfd3da

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -37
app.py CHANGED
@@ -11,6 +11,10 @@ from threading import Thread
11
  text_gen=gr.Interface.load("spaces/Omnibus/MagicPrompt-Stable-Diffusion")
12
  proc1=gr.Interface.load("models/dreamlike-art/dreamlike-diffusion-1.0", live=True)
13
 
 
 
 
 
14
  def restart_script_periodically():
15
  while True:
16
  time.sleep(600) # 10 minutes
@@ -19,16 +23,6 @@ def restart_script_periodically():
19
  restart_thread = Thread(target=restart_script_periodically, daemon=True)
20
  restart_thread.start()
21
 
22
- def reset_queue_periodically():
23
- start_time = time.time()
24
- while True:
25
- if time.time() - start_time >= 120: # 5 minutes
26
- queue.queue.clear()
27
- start_time = time.time()
28
-
29
- reset_queue_thread = Thread(target=reset_queue_periodically, daemon=True)
30
- reset_queue_thread.start()
31
-
32
  queue = Queue()
33
  queue_threshold = 50
34
 
@@ -54,8 +48,7 @@ def send_it1(inputs, noise_level, proc1=proc1):
54
  while queue.qsize() >= queue_threshold:
55
  time.sleep(2)
56
  queue.put(prompt_with_noise)
57
- output1 = proc1(queue.get())
58
- queue.queue.clear() # Clear the queue after the output is generated
59
  return output1
60
 
61
  def send_it2(inputs, noise_level, proc1=proc1):
@@ -63,8 +56,7 @@ def send_it2(inputs, noise_level, proc1=proc1):
63
  while queue.qsize() >= queue_threshold:
64
  time.sleep(2)
65
  queue.put(prompt_with_noise)
66
- output2 = proc1(queue.get())
67
- queue.queue.clear() # Clear the queue after the output is generated
68
  return output2
69
 
70
  def send_it3(inputs, noise_level, proc1=proc1):
@@ -72,8 +64,7 @@ def send_it3(inputs, noise_level, proc1=proc1):
72
  while queue.qsize() >= queue_threshold:
73
  time.sleep(2)
74
  queue.put(prompt_with_noise)
75
- output3 = proc1(queue.get())
76
- queue.queue.clear() # Clear the queue after the output is generated
77
  return output3
78
 
79
  def send_it4(inputs, noise_level, proc1=proc1):
@@ -81,8 +72,7 @@ def send_it4(inputs, noise_level, proc1=proc1):
81
  while queue.qsize() >= queue_threshold:
82
  time.sleep(2)
83
  queue.put(prompt_with_noise)
84
- output4 = proc1(queue.get())
85
- queue.queue.clear() # Clear the queue after the output is generated
86
  return output4
87
 
88
  def send_it5(inputs, noise_level, proc1=proc1):
@@ -90,8 +80,7 @@ def send_it5(inputs, noise_level, proc1=proc1):
90
  while queue.qsize() >= queue_threshold:
91
  time.sleep(2)
92
  queue.put(prompt_with_noise)
93
- output5 = proc1(queue.get())
94
- queue.queue.clear() # Clear the queue after the output is generated
95
  return output5
96
 
97
  def send_it6(inputs, noise_level, proc1=proc1):
@@ -99,8 +88,7 @@ def send_it6(inputs, noise_level, proc1=proc1):
99
  while queue.qsize() >= queue_threshold:
100
  time.sleep(2)
101
  queue.put(prompt_with_noise)
102
- output6 = proc1(queue.get())
103
- queue.queue.clear() # Clear the queue after the output is generated
104
  return output6
105
 
106
  def send_it7(inputs, noise_level, proc1=proc1):
@@ -108,8 +96,7 @@ def send_it7(inputs, noise_level, proc1=proc1):
108
  while queue.qsize() >= queue_threshold:
109
  time.sleep(2)
110
  queue.put(prompt_with_noise)
111
- output7 = proc1(queue.get())
112
- queue.queue.clear() # Clear the queue after the output is generated
113
  return output7
114
 
115
  def send_it8(inputs, noise_level, proc1=proc1):
@@ -117,20 +104,10 @@ def send_it8(inputs, noise_level, proc1=proc1):
117
  while queue.qsize() >= queue_threshold:
118
  time.sleep(2)
119
  queue.put(prompt_with_noise)
120
- output8 = proc1(queue.get())
121
- queue.queue.clear() # Clear the queue after the output is generated
122
  return output8
123
 
124
 
125
- def get_prompts(prompt_text):
126
- while queue.qsize() >= queue_threshold:
127
- time.sleep(2)
128
- queue.put(prompt_text)
129
- output = text_gen(queue.get())
130
- queue.queue.clear() # Clear the queue after the output is generated
131
- return output
132
-
133
-
134
  with gr.Blocks() as myface:
135
  with gr.Row():
136
 
@@ -169,5 +146,4 @@ with gr.Blocks() as myface:
169
  see_prompts.click(get_prompts, inputs=[input_text], outputs=[prompt])
170
 
171
  myface.launch(enable_queue=True, inline=True)
172
- block.queue(concurrency_count=30, max_size=30)
173
- reset_queue_thread.join()
 
11
  text_gen=gr.Interface.load("spaces/Omnibus/MagicPrompt-Stable-Diffusion")
12
  proc1=gr.Interface.load("models/dreamlike-art/dreamlike-diffusion-1.0", live=True)
13
 
14
+ def get_prompts(prompt_text):
15
+ output = text_gen(prompt_text)
16
+ return output
17
+
18
  def restart_script_periodically():
19
  while True:
20
  time.sleep(600) # 10 minutes
 
23
  restart_thread = Thread(target=restart_script_periodically, daemon=True)
24
  restart_thread.start()
25
 
 
 
 
 
 
 
 
 
 
 
26
  queue = Queue()
27
  queue_threshold = 50
28
 
 
48
  while queue.qsize() >= queue_threshold:
49
  time.sleep(2)
50
  queue.put(prompt_with_noise)
51
+ output1 = proc1(prompt_with_noise)
 
52
  return output1
53
 
54
  def send_it2(inputs, noise_level, proc1=proc1):
 
56
  while queue.qsize() >= queue_threshold:
57
  time.sleep(2)
58
  queue.put(prompt_with_noise)
59
+ output2 = proc1(prompt_with_noise)
 
60
  return output2
61
 
62
  def send_it3(inputs, noise_level, proc1=proc1):
 
64
  while queue.qsize() >= queue_threshold:
65
  time.sleep(2)
66
  queue.put(prompt_with_noise)
67
+ output3 = proc1(prompt_with_noise)
 
68
  return output3
69
 
70
  def send_it4(inputs, noise_level, proc1=proc1):
 
72
  while queue.qsize() >= queue_threshold:
73
  time.sleep(2)
74
  queue.put(prompt_with_noise)
75
+ output4 = proc1(prompt_with_noise)
 
76
  return output4
77
 
78
  def send_it5(inputs, noise_level, proc1=proc1):
 
80
  while queue.qsize() >= queue_threshold:
81
  time.sleep(2)
82
  queue.put(prompt_with_noise)
83
+ output5 = proc1(prompt_with_noise)
 
84
  return output5
85
 
86
  def send_it6(inputs, noise_level, proc1=proc1):
 
88
  while queue.qsize() >= queue_threshold:
89
  time.sleep(2)
90
  queue.put(prompt_with_noise)
91
+ output6 = proc1(prompt_with_noise)
 
92
  return output6
93
 
94
  def send_it7(inputs, noise_level, proc1=proc1):
 
96
  while queue.qsize() >= queue_threshold:
97
  time.sleep(2)
98
  queue.put(prompt_with_noise)
99
+ output7 = proc1(prompt_with_noise)
 
100
  return output7
101
 
102
  def send_it8(inputs, noise_level, proc1=proc1):
 
104
  while queue.qsize() >= queue_threshold:
105
  time.sleep(2)
106
  queue.put(prompt_with_noise)
107
+ output8 = proc1(prompt_with_noise)
 
108
  return output8
109
 
110
 
 
 
 
 
 
 
 
 
 
111
  with gr.Blocks() as myface:
112
  with gr.Row():
113
 
 
146
  see_prompts.click(get_prompts, inputs=[input_text], outputs=[prompt])
147
 
148
  myface.launch(enable_queue=True, inline=True)
149
+ block.queue(concurrency_count=30, max_size=30)