Emiir commited on
Commit
2966162
ยท
1 Parent(s): 294bd5f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -44
app.py CHANGED
@@ -9,13 +9,18 @@ from queue import Queue
9
  from threading import Thread
10
  import emoji
11
 
12
- text_gen=gr.Interface.load("spaces/phenomenon1981/MagicPrompt-Stable-Diffusion")
 
 
13
  def get_prompts(prompt_text):
14
  if prompt_text:
15
  return text_gen("dreamlikeart, " + prompt_text)
16
  else:
17
  return text_gen("")
18
- proc1=gr.Interface.load("models/dreamlike-art/dreamlike-diffusion-1.0")
 
 
 
19
 
20
  def restart_script_periodically():
21
  while True:
@@ -27,25 +32,29 @@ def restart_script_periodically():
27
  restart_thread = Thread(target=restart_script_periodically, daemon=True)
28
  restart_thread.start()
29
 
30
-
31
  queue = Queue()
32
  queue_threshold = 100
33
 
 
34
  def add_random_noise(prompt, noise_level=0.00):
35
  if noise_level == 0:
36
  noise_level = 0.00
37
  percentage_noise = noise_level * 5
38
- num_noise_chars = int(len(prompt) * (percentage_noise/100))
39
  noise_indices = random.sample(range(len(prompt)), num_noise_chars)
40
  prompt_list = list(prompt)
41
  noise_chars = list(string.ascii_letters + string.punctuation + ' ' + string.digits)
42
- noise_chars.extend(['๐Ÿ˜', '๐Ÿ’ฉ', '๐Ÿ˜‚', '๐Ÿค”', '๐Ÿ˜Š', '๐Ÿค—', '๐Ÿ˜ญ', '๐Ÿ™„', '๐Ÿ˜ท', '๐Ÿคฏ', '๐Ÿคซ', '๐Ÿฅด', '๐Ÿ˜ด', '๐Ÿคฉ', '๐Ÿฅณ', '๐Ÿ˜”', '๐Ÿ˜ฉ', '๐Ÿคช', '๐Ÿ˜‡', '๐Ÿคข', '๐Ÿ˜ˆ', '๐Ÿ‘น', '๐Ÿ‘ป', '๐Ÿค–', '๐Ÿ‘ฝ', '๐Ÿ’€', '๐ŸŽƒ', '๐ŸŽ…', '๐ŸŽ„', '๐ŸŽ', '๐ŸŽ‚', '๐ŸŽ‰', '๐ŸŽˆ', '๐ŸŽŠ', '๐ŸŽฎ', 'โค๏ธ', '๐Ÿ’”', '๐Ÿ’•', '๐Ÿ’–', '๐Ÿ’—', '๐Ÿถ', '๐Ÿฑ', '๐Ÿญ', '๐Ÿน', '๐ŸฆŠ', '๐Ÿป', '๐Ÿจ', '๐Ÿฏ', '๐Ÿฆ', '๐Ÿ˜', '๐Ÿ”ฅ', '๐ŸŒง๏ธ', '๐ŸŒž', '๐ŸŒˆ', '๐Ÿ’ฅ', '๐ŸŒด', '๐ŸŒŠ', '๐ŸŒบ', '๐ŸŒป', '๐ŸŒธ', '๐ŸŽจ', '๐ŸŒ…', '๐ŸŒŒ', 'โ˜๏ธ', 'โ›ˆ๏ธ', 'โ„๏ธ', 'โ˜€๏ธ', '๐ŸŒค๏ธ', 'โ›…๏ธ', '๐ŸŒฅ๏ธ', '๐ŸŒฆ๏ธ', '๐ŸŒง๏ธ', '๐ŸŒฉ๏ธ', '๐ŸŒจ๏ธ', '๐ŸŒซ๏ธ', 'โ˜”๏ธ', '๐ŸŒฌ๏ธ', '๐Ÿ’จ', '๐ŸŒช๏ธ', '๐ŸŒˆ'])
 
 
 
 
 
43
  for index in noise_indices:
44
  prompt_list[index] = random.choice(noise_chars)
45
  return "".join(prompt_list)
46
 
47
 
48
-
49
  def send_it1(inputs, noise_level, proc1=proc1):
50
  prompt_with_noise = add_random_noise(inputs, noise_level)
51
  while queue.qsize() >= queue_threshold:
@@ -54,6 +63,7 @@ def send_it1(inputs, noise_level, proc1=proc1):
54
  output1 = proc1(prompt_with_noise)
55
  return output1
56
 
 
57
  def send_it2(inputs, noise_level, proc1=proc1):
58
  prompt_with_noise = add_random_noise(inputs, noise_level)
59
  while queue.qsize() >= queue_threshold:
@@ -62,49 +72,47 @@ def send_it2(inputs, noise_level, proc1=proc1):
62
  output2 = proc1(prompt_with_noise)
63
  return output2
64
 
65
- #def send_it3(inputs, noise_level, proc1=proc1):
66
- #prompt_with_noise = add_random_noise(inputs, noise_level)
67
- #while queue.qsize() >= queue_threshold:
68
- #time.sleep(2)
69
- #queue.put(prompt_with_noise)
70
- #output3 = proc1(prompt_with_noise)
71
- #return output3
72
 
73
- #def send_it4(inputs, noise_level, proc1=proc1):
74
- #prompt_with_noise = add_random_noise(inputs, noise_level)
75
- #while queue.qsize() >= queue_threshold:
76
- #time.sleep(2)
77
- #queue.put(prompt_with_noise)
78
- #output4 = proc1(prompt_with_noise)
79
- #return output4
 
 
 
 
 
 
 
 
80
 
81
 
82
  with gr.Blocks(css='style.css') as demo:
83
-
84
- with gr.Row(variant="compact"):
85
- prompt = gr.Textbox(
86
- label="Enter your prompt",
87
- show_label=False,
88
- max_lines=2,
89
- placeholder="Araรง bilginizi giriniz.",
90
- ).style(
91
- container=False,
92
- )
93
- run = gr.Button("OluลŸtur [Az detaylฤฑ]").style(full_width=False)
94
-
95
  with gr.Row():
96
- with gr.Row():
97
- noise_level = gr.Slider(minimum=0.0, maximum=3, step=0.1, label="Gรถrรผntรผnรผn Gรผrรผltรผ Katsayฤฑsฤฑ")
98
  with gr.Row():
99
- with gr.Row():
100
- output1=gr.Image(label="Dreamlike Diffusion 1.0",show_label=False)
101
- output2=gr.Image(label="Dreamlike Diffusion 1.0",show_label=False)
102
-
103
-
104
- see_prompts.click(get_prompts, inputs=[input_text], outputs=[prompt], queue=False)
105
- run.click(send_it1, inputs=[prompt, noise_level], outputs=[output1])
106
- run.click(send_it2, inputs=[prompt, noise_level], outputs=[output2])
107
 
 
 
 
108
 
109
- demo.launch(enable_queue=True, inline=True)
110
- block.queue(concurrency_count=100)
 
9
  from threading import Thread
10
  import emoji
11
 
12
+ text_gen = gr.Interface.load("spaces/phenomenon1981/MagicPrompt-Stable-Diffusion")
13
+
14
+
15
  def get_prompts(prompt_text):
16
  if prompt_text:
17
  return text_gen("dreamlikeart, " + prompt_text)
18
  else:
19
  return text_gen("")
20
+
21
+
22
+ proc1 = gr.Interface.load("models/dreamlike-art/dreamlike-diffusion-1.0")
23
+
24
 
25
  def restart_script_periodically():
26
  while True:
 
32
  restart_thread = Thread(target=restart_script_periodically, daemon=True)
33
  restart_thread.start()
34
 
 
35
  queue = Queue()
36
  queue_threshold = 100
37
 
38
+
39
  def add_random_noise(prompt, noise_level=0.00):
40
  if noise_level == 0:
41
  noise_level = 0.00
42
  percentage_noise = noise_level * 5
43
+ num_noise_chars = int(len(prompt) * (percentage_noise / 100))
44
  noise_indices = random.sample(range(len(prompt)), num_noise_chars)
45
  prompt_list = list(prompt)
46
  noise_chars = list(string.ascii_letters + string.punctuation + ' ' + string.digits)
47
+ noise_chars.extend(
48
+ ['๐Ÿ˜', '๐Ÿ’ฉ', '๐Ÿ˜‚', '๐Ÿค”', '๐Ÿ˜Š', '๐Ÿค—', '๐Ÿ˜ญ', '๐Ÿ™„', '๐Ÿ˜ท', '๐Ÿคฏ', '๐Ÿคซ', '๐Ÿฅด', '๐Ÿ˜ด', '๐Ÿคฉ', '๐Ÿฅณ', '๐Ÿ˜”', '๐Ÿ˜ฉ', '๐Ÿคช',
49
+ '๐Ÿ˜‡', '๐Ÿคข', '๐Ÿ˜ˆ', '๐Ÿ‘น', '๐Ÿ‘ป', '๐Ÿค–', '๐Ÿ‘ฝ', '๐Ÿ’€', '๐ŸŽƒ', '๐ŸŽ…', '๐ŸŽ„', '๐ŸŽ', '๐ŸŽ‚', '๐ŸŽ‰', '๐ŸŽˆ', '๐ŸŽŠ', '๐ŸŽฎ', 'โค๏ธ',
50
+ '๐Ÿ’”', '๐Ÿ’•', '๐Ÿ’–', '๐Ÿ’—', '๐Ÿถ', '๐Ÿฑ', '๐Ÿญ', '๐Ÿน', '๐ŸฆŠ', '๐Ÿป', '๐Ÿจ', '๐Ÿฏ', '๐Ÿฆ', '๐Ÿ˜', '๐Ÿ”ฅ', '๐ŸŒง๏ธ', '๐ŸŒž', '๐ŸŒˆ',
51
+ '๐Ÿ’ฅ', '๐ŸŒด', '๐ŸŒŠ', '๐ŸŒบ', '๐ŸŒป', '๐ŸŒธ', '๐ŸŽจ', '๐ŸŒ…', '๐ŸŒŒ', 'โ˜๏ธ', 'โ›ˆ๏ธ', 'โ„๏ธ', 'โ˜€๏ธ', '๐ŸŒค๏ธ', 'โ›…๏ธ', '๐ŸŒฅ๏ธ', '๐ŸŒฆ๏ธ', '๐ŸŒง๏ธ',
52
+ '๐ŸŒฉ๏ธ', '๐ŸŒจ๏ธ', '๐ŸŒซ๏ธ', 'โ˜”๏ธ', '๐ŸŒฌ๏ธ', '๐Ÿ’จ', '๐ŸŒช๏ธ', '๐ŸŒˆ'])
53
  for index in noise_indices:
54
  prompt_list[index] = random.choice(noise_chars)
55
  return "".join(prompt_list)
56
 
57
 
 
58
  def send_it1(inputs, noise_level, proc1=proc1):
59
  prompt_with_noise = add_random_noise(inputs, noise_level)
60
  while queue.qsize() >= queue_threshold:
 
63
  output1 = proc1(prompt_with_noise)
64
  return output1
65
 
66
+
67
  def send_it2(inputs, noise_level, proc1=proc1):
68
  prompt_with_noise = add_random_noise(inputs, noise_level)
69
  while queue.qsize() >= queue_threshold:
 
72
  output2 = proc1(prompt_with_noise)
73
  return output2
74
 
 
 
 
 
 
 
 
75
 
76
+ # def send_it3(inputs, noise_level, proc1=proc1):
77
+ # prompt_with_noise = add_random_noise(inputs, noise_level)
78
+ # while queue.qsize() >= queue_threshold:
79
+ # time.sleep(2)
80
+ # queue.put(prompt_with_noise)
81
+ # output3 = proc1(prompt_with_noise)
82
+ # return output3
83
+
84
+ # def send_it4(inputs, noise_level, proc1=proc1):
85
+ # prompt_with_noise = add_random_noise(inputs, noise_level)
86
+ # while queue.qsize() >= queue_threshold:
87
+ # time.sleep(2)
88
+ # queue.put(prompt_with_noise)
89
+ # output4 = proc1(prompt_with_noise)
90
+ # return output4
91
 
92
 
93
  with gr.Blocks(css='style.css') as demo:
94
+ with gr.Row(variant="compact"):
95
+ prompt = gr.Textbox(
96
+ label="Enter your prompt",
97
+ show_label=False,
98
+ max_lines=2,
99
+ placeholder="Araรง bilginizi giriniz.",
100
+ ).style(
101
+ container=False,
102
+ )
103
+ run = gr.Button("OluลŸtur [Az detaylฤฑ]").style(full_width=False)
104
+
105
+ with gr.Row():
106
  with gr.Row():
107
+ noise_level = gr.Slider(minimum=0.0, maximum=3, step=0.1, label="Gรถrรผntรผnรผn Gรผrรผltรผ Katsayฤฑsฤฑ")
108
+ with gr.Row():
109
  with gr.Row():
110
+ output1 = gr.Image(label="Dreamlike Diffusion 1.0", show_label=False)
111
+ output2 = gr.Image(label="Dreamlike Diffusion 1.0", show_label=False)
 
 
 
 
 
 
112
 
113
+ see_prompts.click(get_prompts, inputs=[input_text], outputs=[prompt], queue=False)
114
+ run.click(send_it1, inputs=[prompt, noise_level], outputs=[output1])
115
+ run.click(send_it2, inputs=[prompt, noise_level], outputs=[output2])
116
 
117
+ demo.launch(enable_queue=True, inline=True)
118
+ block.queue(concurrency_count=100)