phenomenon1981 commited on
Commit
16542ca
1 Parent(s): 45358c6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -22
app.py CHANGED
@@ -8,7 +8,7 @@ import time
8
  from queue import Queue
9
  from threading import Thread
10
 
11
- text_gen=gr.Interface.load("spaces/Omnibus/MagicPrompt-Stable-Diffusion")
12
  proc1=gr.Interface.load("models/dreamlike-art/dreamlike-photoreal-2.0", live=True)
13
 
14
  def restart_script_periodically():
@@ -19,16 +19,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 = 9
34
 
@@ -53,7 +43,6 @@ def send_it1(inputs, noise_level, proc1=proc1):
53
  time.sleep(2)
54
  queue.put(prompt_with_noise)
55
  output1 = proc1(queue.get())
56
- queue.queue.clear() # Clear the queue after the output is generated
57
  return output1
58
 
59
  def send_it2(inputs, noise_level, proc1=proc1):
@@ -62,7 +51,6 @@ def send_it2(inputs, noise_level, proc1=proc1):
62
  time.sleep(2)
63
  queue.put(prompt_with_noise)
64
  output2 = proc1(queue.get())
65
- queue.queue.clear() # Clear the queue after the output is generated
66
  return output2
67
 
68
  def send_it3(inputs, noise_level, proc1=proc1):
@@ -71,7 +59,6 @@ def send_it3(inputs, noise_level, proc1=proc1):
71
  time.sleep(2)
72
  queue.put(prompt_with_noise)
73
  output3 = proc1(queue.get())
74
- queue.queue.clear() # Clear the queue after the output is generated
75
  return output3
76
 
77
  def send_it4(inputs, noise_level, proc1=proc1):
@@ -80,7 +67,6 @@ def send_it4(inputs, noise_level, proc1=proc1):
80
  time.sleep(2)
81
  queue.put(prompt_with_noise)
82
  output4 = proc1(queue.get())
83
- queue.queue.clear() # Clear the queue after the output is generated
84
  return output4
85
 
86
  def send_it5(inputs, noise_level, proc1=proc1):
@@ -89,7 +75,6 @@ def send_it5(inputs, noise_level, proc1=proc1):
89
  time.sleep(2)
90
  queue.put(prompt_with_noise)
91
  output5 = proc1(queue.get())
92
- queue.queue.clear() # Clear the queue after the output is generated
93
  return output5
94
 
95
  def send_it6(inputs, noise_level, proc1=proc1):
@@ -98,7 +83,6 @@ def send_it6(inputs, noise_level, proc1=proc1):
98
  time.sleep(2)
99
  queue.put(prompt_with_noise)
100
  output6 = proc1(queue.get())
101
- queue.queue.clear() # Clear the queue after the output is generated
102
  return output6
103
 
104
  def send_it7(inputs, noise_level, proc1=proc1):
@@ -107,7 +91,6 @@ def send_it7(inputs, noise_level, proc1=proc1):
107
  time.sleep(2)
108
  queue.put(prompt_with_noise)
109
  output7 = proc1(queue.get())
110
- queue.queue.clear() # Clear the queue after the output is generated
111
  return output7
112
 
113
  def send_it8(inputs, noise_level, proc1=proc1):
@@ -116,7 +99,6 @@ def send_it8(inputs, noise_level, proc1=proc1):
116
  time.sleep(2)
117
  queue.put(prompt_with_noise)
118
  output8 = proc1(queue.get())
119
- queue.queue.clear() # Clear the queue after the output is generated
120
  return output8
121
 
122
 
@@ -125,7 +107,6 @@ def get_prompts(prompt_text):
125
  time.sleep(2)
126
  queue.put(prompt_text)
127
  output = text_gen(queue.get())
128
- queue.queue.clear() # Clear the queue after the output is generated
129
  return output
130
 
131
 
@@ -167,5 +148,4 @@ with gr.Blocks() as myface:
167
  see_prompts.click(get_prompts, inputs=[input_text], outputs=[prompt])
168
 
169
  myface.launch(enable_queue=True, inline=True)
170
- block.queue(concurrency_count=30, max_size=30)
171
- reset_queue_thread.join()
 
8
  from queue import Queue
9
  from threading import Thread
10
 
11
+ text_gen=gr.Interface.load("spaces/Omnibus/MagicPrompt-Stable-Diffusion", live=True)
12
  proc1=gr.Interface.load("models/dreamlike-art/dreamlike-photoreal-2.0", live=True)
13
 
14
  def restart_script_periodically():
 
19
  restart_thread = Thread(target=restart_script_periodically, daemon=True)
20
  restart_thread.start()
21
 
 
 
 
 
 
 
 
 
 
 
22
  queue = Queue()
23
  queue_threshold = 9
24
 
 
43
  time.sleep(2)
44
  queue.put(prompt_with_noise)
45
  output1 = proc1(queue.get())
 
46
  return output1
47
 
48
  def send_it2(inputs, noise_level, proc1=proc1):
 
51
  time.sleep(2)
52
  queue.put(prompt_with_noise)
53
  output2 = proc1(queue.get())
 
54
  return output2
55
 
56
  def send_it3(inputs, noise_level, proc1=proc1):
 
59
  time.sleep(2)
60
  queue.put(prompt_with_noise)
61
  output3 = proc1(queue.get())
 
62
  return output3
63
 
64
  def send_it4(inputs, noise_level, proc1=proc1):
 
67
  time.sleep(2)
68
  queue.put(prompt_with_noise)
69
  output4 = proc1(queue.get())
 
70
  return output4
71
 
72
  def send_it5(inputs, noise_level, proc1=proc1):
 
75
  time.sleep(2)
76
  queue.put(prompt_with_noise)
77
  output5 = proc1(queue.get())
 
78
  return output5
79
 
80
  def send_it6(inputs, noise_level, proc1=proc1):
 
83
  time.sleep(2)
84
  queue.put(prompt_with_noise)
85
  output6 = proc1(queue.get())
 
86
  return output6
87
 
88
  def send_it7(inputs, noise_level, proc1=proc1):
 
91
  time.sleep(2)
92
  queue.put(prompt_with_noise)
93
  output7 = proc1(queue.get())
 
94
  return output7
95
 
96
  def send_it8(inputs, noise_level, proc1=proc1):
 
99
  time.sleep(2)
100
  queue.put(prompt_with_noise)
101
  output8 = proc1(queue.get())
 
102
  return output8
103
 
104
 
 
107
  time.sleep(2)
108
  queue.put(prompt_text)
109
  output = text_gen(queue.get())
 
110
  return output
111
 
112
 
 
148
  see_prompts.click(get_prompts, inputs=[input_text], outputs=[prompt])
149
 
150
  myface.launch(enable_queue=True, inline=True)
151
+ block.queue(concurrency_count=30, max_size=30)