Pamudu13 commited on
Commit
47ce067
·
verified ·
1 Parent(s): 7487c2b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -47
app.py CHANGED
@@ -1,17 +1,10 @@
1
  import gradio as gr
2
- # import os
3
- # import sys
4
- # from pathlib import Path
5
  import time
6
 
7
- models =[
8
  "John6666/ultimate-realistic-mix-v2-sdxl",
9
- "Yntec/CrystalReality",
10
- "Yntec/ChickFlick",
11
-
12
-
13
  ]
14
-
15
 
16
  model_functions = {}
17
  model_idx = 1
@@ -20,12 +13,9 @@ for model_path in models:
20
  model_functions[model_idx] = gr.Interface.load(f"models/{model_path}", live=False, preprocess=True, postprocess=False)
21
  except Exception as error:
22
  def the_fn(txt):
23
-
24
  return None
25
  model_functions[model_idx] = gr.Interface(fn=the_fn, inputs=["text"], outputs=["image"])
26
-
27
- model_idx+=1
28
-
29
 
30
  def send_it_idx(idx):
31
  def send_it_fn(prompt):
@@ -34,7 +24,6 @@ def send_it_idx(idx):
34
  return send_it_fn
35
 
36
  def get_prompts(prompt_text):
37
-
38
  return prompt_text
39
 
40
  def clear_it(val):
@@ -42,51 +31,48 @@ def clear_it(val):
42
  val = 0
43
  else:
44
  val = 0
45
- pass
46
  return val
47
 
48
- def all_task_end(cnt,t_stamp):
49
  to = t_stamp + 360
50
  et = time.time()
51
  if et > to and t_stamp != 0:
52
  d = gr.update(value=0)
53
  tog = gr.update(value=1)
54
- #print(f'to: {to} et: {et}')
55
  else:
56
  if cnt != 0:
57
  d = gr.update(value=et)
58
  else:
59
  d = gr.update(value=0)
60
  tog = gr.update(value=0)
61
- #print (f'passing: to: {to} et: {et}')
62
- pass
63
  return d, tog
64
 
65
  def all_task_start():
66
- print("\n\n\n\n\n\n\n")
67
  t = time.gmtime()
68
  t_stamp = time.time()
69
- current_time = time.strftime("%H:%M:%S", t)
70
  return gr.update(value=t_stamp), gr.update(value=t_stamp), gr.update(value=0)
71
 
72
  def clear_fn():
73
  nn = len(models)
74
  return tuple([None, *[None for _ in range(nn)]])
75
 
 
 
 
 
 
 
 
76
 
77
  with gr.Blocks(title="SD Models") as my_interface:
78
  with gr.Column(scale=12):
79
- # with gr.Row():
80
- # gr.Markdown("""- Primary prompt: 你想画的内容(英文单词,如 a cat, 加英文逗号效果更好;点 Improve 按钮进行完善)\n- Real prompt: 完善后的提示词,出现后再点右边的 Run 按钮开始运行""")
81
  with gr.Row():
82
  with gr.Row(scale=6):
83
- primary_prompt=gr.Textbox(label="Prompt", value="")
84
- # real_prompt=gr.Textbox(label="Real prompt")
85
  with gr.Row(scale=6):
86
- # improve_prompts_btn=gr.Button("Improve")
87
  with gr.Row():
88
- run=gr.Button("Run",variant="primary")
89
- clear_btn=gr.Button("Clear")
90
  with gr.Row():
91
  sd_outputs = {}
92
  model_idx = 1
@@ -94,49 +80,46 @@ with gr.Blocks(title="SD Models") as my_interface:
94
  with gr.Column(scale=3, min_width=320):
95
  with gr.Box():
96
  sd_outputs[model_idx] = gr.Image(label=model_path)
97
- pass
98
  model_idx += 1
99
- pass
100
- pass
101
 
102
  with gr.Row(visible=False):
103
- start_box=gr.Number(interactive=False)
104
- end_box=gr.Number(interactive=False)
105
- tog_box=gr.Textbox(value=0,interactive=False)
106
 
107
  start_box.change(
108
  all_task_end,
109
  [start_box, end_box],
110
  [start_box, tog_box],
111
  every=1,
112
- show_progress=True)
 
113
 
114
  primary_prompt.submit(all_task_start, None, [start_box, end_box, tog_box])
115
  run.click(all_task_start, None, [start_box, end_box, tog_box])
 
116
  runs_dict = {}
117
  model_idx = 1
118
  for model_path in models:
119
  runs_dict[model_idx] = run.click(model_functions[model_idx], inputs=[primary_prompt], outputs=[sd_outputs[model_idx]])
120
  model_idx += 1
121
- pass
122
- pass
123
-
124
- # improve_prompts_btn_clicked=improve_prompts_btn.click(
125
- # get_prompts,
126
- # inputs=[primary_prompt],
127
- # outputs=[primary_prompt],
128
- # cancels=list(runs_dict.values()))
129
  clear_btn.click(
130
  clear_fn,
131
  None,
132
  [primary_prompt, *list(sd_outputs.values())],
133
- cancels=[*list(runs_dict.values())])
 
134
  tog_box.change(
135
  clear_it,
136
  tog_box,
137
  tog_box,
138
- cancels=[*list(runs_dict.values())])
139
- text_gen1=gr.Interface.load("spaces/phenomenon1981/MagicPrompt-Stable-Diffusion")
 
 
 
 
140
 
141
  my_interface.queue(concurrency_count=600, status_update_rate=1)
142
- my_interface.launch(inline=True, show_api=True)
 
1
  import gradio as gr
2
+ import random
 
 
3
  import time
4
 
5
+ models = [
6
  "John6666/ultimate-realistic-mix-v2-sdxl",
 
 
 
 
7
  ]
 
8
 
9
  model_functions = {}
10
  model_idx = 1
 
13
  model_functions[model_idx] = gr.Interface.load(f"models/{model_path}", live=False, preprocess=True, postprocess=False)
14
  except Exception as error:
15
  def the_fn(txt):
 
16
  return None
17
  model_functions[model_idx] = gr.Interface(fn=the_fn, inputs=["text"], outputs=["image"])
18
+ model_idx += 1
 
 
19
 
20
  def send_it_idx(idx):
21
  def send_it_fn(prompt):
 
24
  return send_it_fn
25
 
26
  def get_prompts(prompt_text):
 
27
  return prompt_text
28
 
29
  def clear_it(val):
 
31
  val = 0
32
  else:
33
  val = 0
 
34
  return val
35
 
36
+ def all_task_end(cnt, t_stamp):
37
  to = t_stamp + 360
38
  et = time.time()
39
  if et > to and t_stamp != 0:
40
  d = gr.update(value=0)
41
  tog = gr.update(value=1)
 
42
  else:
43
  if cnt != 0:
44
  d = gr.update(value=et)
45
  else:
46
  d = gr.update(value=0)
47
  tog = gr.update(value=0)
 
 
48
  return d, tog
49
 
50
  def all_task_start():
 
51
  t = time.gmtime()
52
  t_stamp = time.time()
 
53
  return gr.update(value=t_stamp), gr.update(value=t_stamp), gr.update(value=0)
54
 
55
  def clear_fn():
56
  nn = len(models)
57
  return tuple([None, *[None for _ in range(nn)]])
58
 
59
+ def generate_random_images():
60
+ prompt = "Random seed image"
61
+ outputs = []
62
+ for _ in range(3):
63
+ output = model_functions[1](prompt)
64
+ outputs.append(output)
65
+ return outputs
66
 
67
  with gr.Blocks(title="SD Models") as my_interface:
68
  with gr.Column(scale=12):
 
 
69
  with gr.Row():
70
  with gr.Row(scale=6):
71
+ primary_prompt = gr.Textbox(label="Prompt", value="")
 
72
  with gr.Row(scale=6):
 
73
  with gr.Row():
74
+ run = gr.Button("Run", variant="primary")
75
+ clear_btn = gr.Button("Clear")
76
  with gr.Row():
77
  sd_outputs = {}
78
  model_idx = 1
 
80
  with gr.Column(scale=3, min_width=320):
81
  with gr.Box():
82
  sd_outputs[model_idx] = gr.Image(label=model_path)
 
83
  model_idx += 1
 
 
84
 
85
  with gr.Row(visible=False):
86
+ start_box = gr.Number(interactive=False)
87
+ end_box = gr.Number(interactive=False)
88
+ tog_box = gr.Textbox(value=0, interactive=False)
89
 
90
  start_box.change(
91
  all_task_end,
92
  [start_box, end_box],
93
  [start_box, tog_box],
94
  every=1,
95
+ show_progress=True
96
+ )
97
 
98
  primary_prompt.submit(all_task_start, None, [start_box, end_box, tog_box])
99
  run.click(all_task_start, None, [start_box, end_box, tog_box])
100
+
101
  runs_dict = {}
102
  model_idx = 1
103
  for model_path in models:
104
  runs_dict[model_idx] = run.click(model_functions[model_idx], inputs=[primary_prompt], outputs=[sd_outputs[model_idx]])
105
  model_idx += 1
106
+
 
 
 
 
 
 
 
107
  clear_btn.click(
108
  clear_fn,
109
  None,
110
  [primary_prompt, *list(sd_outputs.values())],
111
+ cancels=[*list(runs_dict.values())]
112
+ )
113
  tog_box.change(
114
  clear_it,
115
  tog_box,
116
  tog_box,
117
+ cancels=[*list(runs_dict.values())]
118
+ )
119
+
120
+ random_images = generate_random_images()
121
+ for i, img in enumerate(random_images):
122
+ sd_outputs[i+1].update(value=img)
123
 
124
  my_interface.queue(concurrency_count=600, status_update_rate=1)
125
+ my_interface.launch(inline=True, show_api=True)