phenomenon1981 commited on
Commit
b0a0637
1 Parent(s): c13b5f3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -17
app.py CHANGED
@@ -5,6 +5,10 @@ from pathlib import Path
5
  import random
6
  import string
7
  import time
 
 
 
 
8
 
9
  text_gen=gr.Interface.load("spaces/Omnibus/MagicPrompt-Stable-Diffusion")
10
 
@@ -19,52 +23,53 @@ def add_random_noise(prompt, noise_level=0.1):
19
 
20
  def send_it1(inputs, noise_level, proc1=proc1):
21
  prompt_with_noise = add_random_noise(inputs, noise_level)
22
- output1=proc1(prompt_with_noise)
23
- time.sleep(1)
24
  return output1
25
 
26
  def send_it2(inputs, noise_level, proc1=proc1):
27
  prompt_with_noise = add_random_noise(inputs, noise_level)
28
- output2=proc1(prompt_with_noise)
29
- time.sleep(1)
30
  return output2
31
 
32
  def send_it3(inputs, noise_level, proc1=proc1):
33
  prompt_with_noise = add_random_noise(inputs, noise_level)
34
- output3=proc1(prompt_with_noise)
35
- time.sleep(1)
36
  return output3
37
 
38
  def send_it4(inputs, noise_level, proc1=proc1):
39
  prompt_with_noise = add_random_noise(inputs, noise_level)
40
- output4=proc1(prompt_with_noise)
41
- time.sleep(1)
42
  return output4
43
 
44
  def send_it5(inputs, noise_level, proc5=proc5):
45
  prompt_with_noise = add_random_noise(inputs, noise_level)
46
- output5=proc5(prompt_with_noise)
47
- time.sleep(1)
48
  return output5
49
 
50
  def send_it6(inputs, noise_level, proc5=proc5):
51
  prompt_with_noise = add_random_noise(inputs, noise_level)
52
- output6=proc5(prompt_with_noise)
53
- time.sleep(1)
54
  return output6
55
 
56
  def send_it7(inputs, noise_level, proc5=proc5):
57
  prompt_with_noise = add_random_noise(inputs, noise_level)
58
- output7=proc5(prompt_with_noise)
59
- time.sleep(1)
60
  return output7
61
 
62
  def send_it8(inputs, noise_level, proc5=proc5):
63
  prompt_with_noise = add_random_noise(inputs, noise_level)
64
- output8=proc5(prompt_with_noise)
65
- time.sleep(1)
66
  return output8
67
 
 
68
  def get_prompts(prompt_text):
69
  return text_gen(prompt_text)
70
 
@@ -104,4 +109,4 @@ with gr.Blocks() as myface:
104
  see_prompts.click(get_prompts, inputs=[input_text], outputs=[prompt])
105
 
106
  myface.queue(concurrency_count=16)
107
- myface.launch(enable_queue=True, queue_maxsize=10, inline=True)
 
5
  import random
6
  import string
7
  import time
8
+ from ratelimiter import RateLimiter
9
+
10
+ # rate limit to 4 calls per second
11
+ rate_limiter = RateLimiter(max_calls=4, period=1)
12
 
13
  text_gen=gr.Interface.load("spaces/Omnibus/MagicPrompt-Stable-Diffusion")
14
 
 
23
 
24
  def send_it1(inputs, noise_level, proc1=proc1):
25
  prompt_with_noise = add_random_noise(inputs, noise_level)
26
+ rate_limiter()
27
+ output1 = proc1(prompt_with_noise)
28
  return output1
29
 
30
  def send_it2(inputs, noise_level, proc1=proc1):
31
  prompt_with_noise = add_random_noise(inputs, noise_level)
32
+ rate_limiter()
33
+ output2 = proc1(prompt_with_noise)
34
  return output2
35
 
36
  def send_it3(inputs, noise_level, proc1=proc1):
37
  prompt_with_noise = add_random_noise(inputs, noise_level)
38
+ rate_limiter()
39
+ output3 = proc1(prompt_with_noise)
40
  return output3
41
 
42
  def send_it4(inputs, noise_level, proc1=proc1):
43
  prompt_with_noise = add_random_noise(inputs, noise_level)
44
+ rate_limiter()
45
+ output4 = proc1(prompt_with_noise)
46
  return output4
47
 
48
  def send_it5(inputs, noise_level, proc5=proc5):
49
  prompt_with_noise = add_random_noise(inputs, noise_level)
50
+ rate_limiter()
51
+ output5 = proc5(prompt_with_noise)
52
  return output5
53
 
54
  def send_it6(inputs, noise_level, proc5=proc5):
55
  prompt_with_noise = add_random_noise(inputs, noise_level)
56
+ rate_limiter()
57
+ output6 = proc5(prompt_with_noise)
58
  return output6
59
 
60
  def send_it7(inputs, noise_level, proc5=proc5):
61
  prompt_with_noise = add_random_noise(inputs, noise_level)
62
+ rate_limiter()
63
+ output7 = proc5(prompt_with_noise)
64
  return output7
65
 
66
  def send_it8(inputs, noise_level, proc5=proc5):
67
  prompt_with_noise = add_random_noise(inputs, noise_level)
68
+ rate_limiter()
69
+ output8 = proc5(prompt_with_noise)
70
  return output8
71
 
72
+
73
  def get_prompts(prompt_text):
74
  return text_gen(prompt_text)
75
 
 
109
  see_prompts.click(get_prompts, inputs=[input_text], outputs=[prompt])
110
 
111
  myface.queue(concurrency_count=16)
112
+ myface.launch(enable_queue=True, inline=True)