phenomenon1981 commited on
Commit
85f710a
1 Parent(s): 47b2630

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -68
app.py CHANGED
@@ -20,7 +20,7 @@ restart_thread = Thread(target=restart_script_periodically, daemon=True)
20
  restart_thread.start()
21
 
22
  queue = Queue()
23
- queue_threshold = 25
24
 
25
  queue_length_counter = 0
26
 
@@ -40,103 +40,70 @@ def add_random_noise(prompt, noise_level=0.07):
40
 
41
 
42
  def send_it1(inputs, noise_level, proc1=proc1):
43
- global queue_length_counter
44
  prompt_with_noise = add_random_noise(inputs, noise_level)
45
- queue_length_counter += 1
46
- output1 = proc1(prompt_with_noise)
47
- queue_length_counter -= 1
48
- if queue_length_counter > 25:
49
- queue.queue.clear()
50
- queue_length_counter = 0
51
- time.sleep(2)
52
  return output1
53
 
54
  def send_it2(inputs, noise_level, proc1=proc1):
55
- global queue_length_counter
56
  prompt_with_noise = add_random_noise(inputs, noise_level)
57
- queue_length_counter += 1
58
- output2 = proc1(prompt_with_noise)
59
- queue_length_counter -= 1
60
- if queue_length_counter > 25:
61
- queue.queue.clear()
62
- queue_length_counter = 0
63
- time.sleep(2)
64
  return output2
65
 
66
  def send_it3(inputs, noise_level, proc1=proc1):
67
- global queue_length_counter
68
  prompt_with_noise = add_random_noise(inputs, noise_level)
69
- queue_length_counter += 1
70
- output3 = proc1(prompt_with_noise)
71
- queue_length_counter -= 1
72
- if queue_length_counter > 25:
73
- queue.queue.clear()
74
- queue_length_counter = 0
75
- time.sleep(2)
76
  return output3
77
 
78
  def send_it4(inputs, noise_level, proc1=proc1):
79
- global queue_length_counter
80
  prompt_with_noise = add_random_noise(inputs, noise_level)
81
- queue_length_counter += 1
82
- output4 = proc1(prompt_with_noise)
83
- queue_length_counter -= 1
84
- if queue_length_counter > 25:
85
- queue.queue.clear()
86
- queue_length_counter = 0
87
- time.sleep(2)
88
  return output4
89
 
90
  def send_it5(inputs, noise_level, proc1=proc1):
91
- global queue_length_counter
92
  prompt_with_noise = add_random_noise(inputs, noise_level)
93
- queue_length_counter += 1
94
- output5 = proc1(prompt_with_noise)
95
- queue_length_counter -= 1
96
- if queue_length_counter > 25:
97
- queue.queue.clear()
98
- queue_length_counter = 0
99
- time.sleep(2)
100
  return output5
101
 
102
  def send_it6(inputs, noise_level, proc1=proc1):
103
- global queue_length_counter
104
  prompt_with_noise = add_random_noise(inputs, noise_level)
105
- queue_length_counter += 1
106
- output6 = proc1(prompt_with_noise)
107
- queue_length_counter -= 1
108
- if queue_length_counter > 25:
109
- queue.queue.clear()
110
- queue_length_counter = 0
111
- time.sleep(2)
112
  return output6
113
 
114
  def send_it7(inputs, noise_level, proc1=proc1):
115
- global queue_length_counter
116
  prompt_with_noise = add_random_noise(inputs, noise_level)
117
- queue_length_counter += 1
118
- output7 = proc1(prompt_with_noise)
119
- queue_length_counter -= 1
120
- if queue_length_counter > 25:
121
- queue.queue.clear()
122
- queue_length_counter = 0
123
- time.sleep(2)
124
  return output7
125
 
126
  def send_it8(inputs, noise_level, proc1=proc1):
127
- global queue_length_counter
128
  prompt_with_noise = add_random_noise(inputs, noise_level)
129
- queue_length_counter += 1
130
- output8 = proc1(prompt_with_noise)
131
- queue_length_counter -= 1
132
- if queue_length_counter > 25:
133
- queue.queue.clear()
134
- queue_length_counter = 0
135
- time.sleep(1)
136
  return output8
137
 
138
 
139
-
140
  def get_prompts(prompt_text):
141
  global queue_length_counter
142
  queue_length_counter += 1
@@ -186,5 +153,6 @@ with gr.Blocks() as myface:
186
  run.click(send_it8, inputs=[prompt, noise_level], outputs=[output8])
187
  see_prompts.click(get_prompts, inputs=[input_text], outputs=[prompt])
188
 
189
- myface.queue(concurrency_count=15)
190
- myface.launch(enable_queue=True, inline=True)
 
 
20
  restart_thread.start()
21
 
22
  queue = Queue()
23
+ queue_threshold = 15
24
 
25
  queue_length_counter = 0
26
 
 
40
 
41
 
42
  def send_it1(inputs, noise_level, proc1=proc1):
 
43
  prompt_with_noise = add_random_noise(inputs, noise_level)
44
+ while queue.qsize() >= queue_threshold:
45
+ time.sleep(1)
46
+ queue.put(prompt_with_noise)
47
+ output1 = proc1(queue.get())
 
 
 
48
  return output1
49
 
50
  def send_it2(inputs, noise_level, proc1=proc1):
 
51
  prompt_with_noise = add_random_noise(inputs, noise_level)
52
+ while queue.qsize() >= queue_threshold:
53
+ time.sleep(1)
54
+ queue.put(prompt_with_noise)
55
+ output2 = proc1(queue.get())
 
 
 
56
  return output2
57
 
58
  def send_it3(inputs, noise_level, proc1=proc1):
 
59
  prompt_with_noise = add_random_noise(inputs, noise_level)
60
+ while queue.qsize() >= queue_threshold:
61
+ time.sleep(1)
62
+ queue.put(prompt_with_noise)
63
+ output3 = proc1(queue.get())
 
 
 
64
  return output3
65
 
66
  def send_it4(inputs, noise_level, proc1=proc1):
 
67
  prompt_with_noise = add_random_noise(inputs, noise_level)
68
+ while queue.qsize() >= queue_threshold:
69
+ time.sleep(1)
70
+ queue.put(prompt_with_noise)
71
+ output4 = proc1(queue.get())
 
 
 
72
  return output4
73
 
74
  def send_it5(inputs, noise_level, proc1=proc1):
 
75
  prompt_with_noise = add_random_noise(inputs, noise_level)
76
+ while queue.qsize() >= queue_threshold:
77
+ time.sleep(1)
78
+ queue.put(prompt_with_noise)
79
+ output5 = proc1(queue.get())
 
 
 
80
  return output5
81
 
82
  def send_it6(inputs, noise_level, proc1=proc1):
 
83
  prompt_with_noise = add_random_noise(inputs, noise_level)
84
+ while queue.qsize() >= queue_threshold:
85
+ time.sleep(1)
86
+ queue.put(prompt_with_noise)
87
+ output6 = proc1(queue.get())
 
 
 
88
  return output6
89
 
90
  def send_it7(inputs, noise_level, proc1=proc1):
 
91
  prompt_with_noise = add_random_noise(inputs, noise_level)
92
+ while queue.qsize() >= queue_threshold:
93
+ time.sleep(1)
94
+ queue.put(prompt_with_noise)
95
+ output7 = proc1(queue.get())
 
 
 
96
  return output7
97
 
98
  def send_it8(inputs, noise_level, proc1=proc1):
 
99
  prompt_with_noise = add_random_noise(inputs, noise_level)
100
+ while queue.qsize() >= queue_threshold:
101
+ time.sleep(1)
102
+ queue.put(prompt_with_noise)
103
+ output8 = proc1(queue.get())
 
 
 
104
  return output8
105
 
106
 
 
107
  def get_prompts(prompt_text):
108
  global queue_length_counter
109
  queue_length_counter += 1
 
153
  run.click(send_it8, inputs=[prompt, noise_level], outputs=[output8])
154
  see_prompts.click(get_prompts, inputs=[input_text], outputs=[prompt])
155
 
156
+ myface.launch(enable_queue=True, inline=True)
157
+ block.queue(concurrency_count=15, max_size=30).launch(max_threads=20)
158
+ reset_queue_thread.join()