phenomenon1981 commited on
Commit
1abcbac
1 Parent(s): 371e039

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -2
app.py CHANGED
@@ -24,6 +24,17 @@ restart_thread = Thread(target=restart_script_periodically, daemon=True)
24
  restart_thread.start()
25
 
26
 
 
 
 
 
 
 
 
 
 
 
 
27
  def add_random_noise(prompt, noise_level=0.07):
28
  # Get the percentage of characters to add as noise
29
  percentage_noise = noise_level * 5
@@ -105,7 +116,10 @@ def send_it8(inputs, noise_level, proc1=proc1):
105
 
106
 
107
  def get_prompts(prompt_text):
108
- output = text_gen(prompt_text)
 
 
 
109
  return output
110
 
111
 
@@ -148,4 +162,11 @@ with gr.Blocks() as myface:
148
 
149
  myface.launch(enable_queue=True, inline=True)
150
  block.queue(concurrency_count=15, max_size=30).launch(max_threads=20)
151
- restart_thread.join()
 
 
 
 
 
 
 
 
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
40
  percentage_noise = noise_level * 5
 
116
 
117
 
118
  def get_prompts(prompt_text):
119
+ while queue.qsize() >= queue_threshold:
120
+ time.sleep(1)
121
+ queue.put(prompt_text)
122
+ output = text_gen(queue.get())
123
  return output
124
 
125
 
 
162
 
163
  myface.launch(enable_queue=True, inline=True)
164
  block.queue(concurrency_count=15, max_size=30).launch(max_threads=20)
165
+ def restart_script_periodically():
166
+ while True:
167
+ time.sleep(120) # 5 minutes
168
+ os.execl(sys.executable, sys.executable, *sys.argv)
169
+
170
+ restart_thread = Thread(target=restart_script_periodically, daemon=True)
171
+ restart_thread.start()
172
+ reset_queue_thread.join()