Spaces:
Runtime error
Runtime error
phenomenon1981
commited on
Commit
·
839e16a
1
Parent(s):
394ac91
Update app.py
Browse files
app.py
CHANGED
@@ -23,17 +23,7 @@ def restart_script_periodically():
|
|
23 |
restart_thread = Thread(target=restart_script_periodically, daemon=True)
|
24 |
restart_thread.start()
|
25 |
|
26 |
-
|
27 |
-
def reset_queue_periodically():
|
28 |
-
start_time = time.time()
|
29 |
-
while True:
|
30 |
-
if time.time() - start_time >= 300: # 5 minutes
|
31 |
-
queue.queue.clear()
|
32 |
-
start_time = time.time()
|
33 |
-
|
34 |
-
reset_queue_thread = Thread(target=reset_queue_periodically, daemon=True)
|
35 |
-
reset_queue_thread.start()
|
36 |
-
|
37 |
|
38 |
def add_random_noise(prompt, noise_level=0.07):
|
39 |
# Get the percentage of characters to add as noise
|
@@ -51,75 +41,112 @@ def add_random_noise(prompt, noise_level=0.07):
|
|
51 |
|
52 |
|
53 |
def send_it1(inputs, noise_level, proc1=proc1):
|
|
|
54 |
prompt_with_noise = add_random_noise(inputs, noise_level)
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
|
|
|
|
|
|
59 |
return output1
|
60 |
|
61 |
def send_it2(inputs, noise_level, proc1=proc1):
|
|
|
62 |
prompt_with_noise = add_random_noise(inputs, noise_level)
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
|
|
|
|
|
|
67 |
return output2
|
68 |
|
69 |
def send_it3(inputs, noise_level, proc1=proc1):
|
|
|
70 |
prompt_with_noise = add_random_noise(inputs, noise_level)
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
|
|
|
|
|
|
75 |
return output3
|
76 |
|
77 |
def send_it4(inputs, noise_level, proc1=proc1):
|
|
|
78 |
prompt_with_noise = add_random_noise(inputs, noise_level)
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
|
|
|
|
|
|
83 |
return output4
|
84 |
|
85 |
def send_it5(inputs, noise_level, proc1=proc1):
|
|
|
86 |
prompt_with_noise = add_random_noise(inputs, noise_level)
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
|
|
|
|
|
|
91 |
return output5
|
92 |
|
93 |
def send_it6(inputs, noise_level, proc1=proc1):
|
|
|
94 |
prompt_with_noise = add_random_noise(inputs, noise_level)
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
|
|
|
|
|
|
99 |
return output6
|
100 |
|
101 |
def send_it7(inputs, noise_level, proc1=proc1):
|
|
|
102 |
prompt_with_noise = add_random_noise(inputs, noise_level)
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
|
|
|
|
|
|
107 |
return output7
|
108 |
|
109 |
def send_it8(inputs, noise_level, proc1=proc1):
|
|
|
110 |
prompt_with_noise = add_random_noise(inputs, noise_level)
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
|
|
|
|
|
|
115 |
return output8
|
116 |
|
117 |
|
|
|
118 |
def get_prompts(prompt_text):
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
|
|
|
|
|
|
|
|
123 |
return output
|
124 |
|
125 |
|
@@ -160,6 +187,5 @@ with gr.Blocks() as myface:
|
|
160 |
run.click(send_it8, inputs=[prompt, noise_level], outputs=[output8])
|
161 |
see_prompts.click(get_prompts, inputs=[input_text], outputs=[prompt])
|
162 |
|
163 |
-
myface.queue(concurrency_count=8)
|
164 |
-
myface.launch(enable_queue=True, inline=True)
|
165 |
-
reset_queue_thread.join()
|
|
|
23 |
restart_thread = Thread(target=restart_script_periodically, daemon=True)
|
24 |
restart_thread.start()
|
25 |
|
26 |
+
queue_length_counter = 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
def add_random_noise(prompt, noise_level=0.07):
|
29 |
# Get the percentage of characters to add as noise
|
|
|
41 |
|
42 |
|
43 |
def send_it1(inputs, noise_level, proc1=proc1):
|
44 |
+
global queue_length_counter
|
45 |
prompt_with_noise = add_random_noise(inputs, noise_level)
|
46 |
+
queue_length_counter += 1
|
47 |
+
output1 = proc1(prompt_with_noise)
|
48 |
+
queue_length_counter -= 1
|
49 |
+
if queue_length_counter > 25:
|
50 |
+
queue.queue.clear()
|
51 |
+
queue_length_counter = 0
|
52 |
+
time.sleep(1)
|
53 |
return output1
|
54 |
|
55 |
def send_it2(inputs, noise_level, proc1=proc1):
|
56 |
+
global queue_length_counter
|
57 |
prompt_with_noise = add_random_noise(inputs, noise_level)
|
58 |
+
queue_length_counter += 1
|
59 |
+
output2 = proc1(prompt_with_noise)
|
60 |
+
queue_length_counter -= 1
|
61 |
+
if queue_length_counter > 25:
|
62 |
+
queue.queue.clear()
|
63 |
+
queue_length_counter = 0
|
64 |
+
time.sleep(1)
|
65 |
return output2
|
66 |
|
67 |
def send_it3(inputs, noise_level, proc1=proc1):
|
68 |
+
global queue_length_counter
|
69 |
prompt_with_noise = add_random_noise(inputs, noise_level)
|
70 |
+
queue_length_counter += 1
|
71 |
+
output3 = proc1(prompt_with_noise)
|
72 |
+
queue_length_counter -= 1
|
73 |
+
if queue_length_counter > 25:
|
74 |
+
queue.queue.clear()
|
75 |
+
queue_length_counter = 0
|
76 |
+
time.sleep(1)
|
77 |
return output3
|
78 |
|
79 |
def send_it4(inputs, noise_level, proc1=proc1):
|
80 |
+
global queue_length_counter
|
81 |
prompt_with_noise = add_random_noise(inputs, noise_level)
|
82 |
+
queue_length_counter += 1
|
83 |
+
output4 = proc1(prompt_with_noise)
|
84 |
+
queue_length_counter -= 1
|
85 |
+
if queue_length_counter > 25:
|
86 |
+
queue.queue.clear()
|
87 |
+
queue_length_counter = 0
|
88 |
+
time.sleep(1)
|
89 |
return output4
|
90 |
|
91 |
def send_it5(inputs, noise_level, proc1=proc1):
|
92 |
+
global queue_length_counter
|
93 |
prompt_with_noise = add_random_noise(inputs, noise_level)
|
94 |
+
queue_length_counter += 1
|
95 |
+
output5 = proc1(prompt_with_noise)
|
96 |
+
queue_length_counter -= 1
|
97 |
+
if queue_length_counter > 25:
|
98 |
+
queue.queue.clear()
|
99 |
+
queue_length_counter = 0
|
100 |
+
time.sleep(1)
|
101 |
return output5
|
102 |
|
103 |
def send_it6(inputs, noise_level, proc1=proc1):
|
104 |
+
global queue_length_counter
|
105 |
prompt_with_noise = add_random_noise(inputs, noise_level)
|
106 |
+
queue_length_counter += 1
|
107 |
+
output6 = proc1(prompt_with_noise)
|
108 |
+
queue_length_counter -= 1
|
109 |
+
if queue_length_counter > 25:
|
110 |
+
queue.queue.clear()
|
111 |
+
queue_length_counter = 0
|
112 |
+
time.sleep(1)
|
113 |
return output6
|
114 |
|
115 |
def send_it7(inputs, noise_level, proc1=proc1):
|
116 |
+
global queue_length_counter
|
117 |
prompt_with_noise = add_random_noise(inputs, noise_level)
|
118 |
+
queue_length_counter += 1
|
119 |
+
output7 = proc1(prompt_with_noise)
|
120 |
+
queue_length_counter -= 1
|
121 |
+
if queue_length_counter > 25:
|
122 |
+
queue.queue.clear()
|
123 |
+
queue_length_counter = 0
|
124 |
+
time.sleep(1)
|
125 |
return output7
|
126 |
|
127 |
def send_it8(inputs, noise_level, proc1=proc1):
|
128 |
+
global queue_length_counter
|
129 |
prompt_with_noise = add_random_noise(inputs, noise_level)
|
130 |
+
queue_length_counter += 1
|
131 |
+
output8 = proc1(prompt_with_noise)
|
132 |
+
queue_length_counter -= 1
|
133 |
+
if queue_length_counter > 25:
|
134 |
+
queue.queue.clear()
|
135 |
+
queue_length_counter = 0
|
136 |
+
time.sleep(1)
|
137 |
return output8
|
138 |
|
139 |
|
140 |
+
|
141 |
def get_prompts(prompt_text):
|
142 |
+
global queue_length_counter
|
143 |
+
queue_length_counter += 1
|
144 |
+
output = text_gen(prompt_text)
|
145 |
+
queue_length_counter -= 1
|
146 |
+
if queue_length_counter > 25:
|
147 |
+
queue.queue.clear()
|
148 |
+
queue_length_counter = 0
|
149 |
+
time.sleep(1)
|
150 |
return output
|
151 |
|
152 |
|
|
|
187 |
run.click(send_it8, inputs=[prompt, noise_level], outputs=[output8])
|
188 |
see_prompts.click(get_prompts, inputs=[input_text], outputs=[prompt])
|
189 |
|
190 |
+
myface.queue(concurrency_count=8)
|
191 |
+
myface.launch(enable_queue=True, inline=True)
|
|