Pamudu13 commited on
Commit
c0f6ca8
·
verified ·
1 Parent(s): c4ede7d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +76 -28
app.py CHANGED
@@ -1,12 +1,17 @@
1
  import gradio as gr
 
 
 
2
  import time
3
- import random
4
 
5
- random_seed = None
 
 
 
 
6
 
7
- models = [
8
- "John6666/ultimate-realistic-mix-v2-sdxl"
9
  ]
 
10
 
11
  model_functions = {}
12
  model_idx = 1
@@ -14,54 +19,74 @@ for model_path in models:
14
  try:
15
  model_functions[model_idx] = gr.Interface.load(f"models/{model_path}", live=False, preprocess=True, postprocess=False)
16
  except Exception as error:
17
- def the_fn(txt, seed=random.randint(0, 2**32 - 1)):
18
- return random.randint(0, 2**32 - 1)
19
- model_functions[model_idx] = gr.Interface(fn=the_fn, inputs=["text", "number"], outputs=["image"])
20
- model_idx += 1
 
 
 
21
 
22
  def send_it_idx(idx):
23
  def send_it_fn(prompt):
24
- global random_seed
25
- output = (model_functions.get(idx) or model_functions.get(1))(prompt, random_seed)
26
  return output
27
  return send_it_fn
28
 
29
  def get_prompts(prompt_text):
 
30
  return prompt_text
31
 
32
  def clear_it(val):
33
- return 0
 
 
 
 
 
34
 
35
- def all_task_end(cnt, t_stamp):
36
  to = t_stamp + 360
37
  et = time.time()
38
  if et > to and t_stamp != 0:
39
  d = gr.update(value=0)
40
  tog = gr.update(value=1)
 
41
  else:
42
- d = gr.update(value=et if cnt != 0 else 0)
 
 
 
43
  tog = gr.update(value=0)
 
 
44
  return d, tog
45
 
46
  def all_task_start():
47
- global random_seed
48
- random_seed = random.randint(0, 2**32 - 1)
49
  t_stamp = time.time()
 
50
  return gr.update(value=t_stamp), gr.update(value=t_stamp), gr.update(value=0)
51
 
52
  def clear_fn():
53
  nn = len(models)
54
  return tuple([None, *[None for _ in range(nn)]])
55
 
 
56
  with gr.Blocks(title="SD Models") as my_interface:
57
  with gr.Column(scale=12):
 
 
58
  with gr.Row():
59
  with gr.Row(scale=6):
60
- primary_prompt = gr.Textbox(label="Prompt", value="")
 
61
  with gr.Row(scale=6):
 
62
  with gr.Row():
63
- run = gr.Button("Run", variant="primary")
64
- clear_btn = gr.Button("Clear")
65
  with gr.Row():
66
  sd_outputs = {}
67
  model_idx = 1
@@ -69,26 +94,49 @@ with gr.Blocks(title="SD Models") as my_interface:
69
  with gr.Column(scale=3, min_width=320):
70
  with gr.Box():
71
  sd_outputs[model_idx] = gr.Image(label=model_path)
 
72
  model_idx += 1
 
 
73
 
74
  with gr.Row(visible=False):
75
- start_box = gr.Number(interactive=False)
76
- end_box = gr.Number(interactive=False)
77
- tog_box = gr.Textbox(value=0, interactive=False)
 
 
 
 
 
 
 
78
 
79
- start_box.change(all_task_end, [start_box, end_box], [start_box, tog_box], every=1, show_progress=True)
80
  primary_prompt.submit(all_task_start, None, [start_box, end_box, tog_box])
81
  run.click(all_task_start, None, [start_box, end_box, tog_box])
82
  runs_dict = {}
83
  model_idx = 1
84
  for model_path in models:
85
- runs_dict[model_idx] = run.click(send_it_idx(model_idx), inputs=[primary_prompt], outputs=[sd_outputs[model_idx]])
86
  model_idx += 1
 
 
87
 
88
- clear_btn.click(clear_fn, None, [primary_prompt, *list(sd_outputs.values())], cancels=[*list(runs_dict.values())])
89
- tog_box.change(clear_it, tog_box, tog_box, cancels=[*list(runs_dict.values())])
90
-
91
- text_gen1 = gr.Interface.load("spaces/phenomenon1981/MagicPrompt-Stable-Diffusion")
 
 
 
 
 
 
 
 
 
 
 
 
92
 
93
  my_interface.queue(concurrency_count=600, status_update_rate=1)
94
- my_interface.launch(inline=True, show_api=True)
 
1
  import gradio as gr
2
+ # import os
3
+ # import sys
4
+ # from pathlib import Path
5
  import time
 
6
 
7
+ models =[
8
+
9
+
10
+ "John6666/9527-detail-realistic-xl-v55mix-sdxl"
11
+
12
 
 
 
13
  ]
14
+
15
 
16
  model_functions = {}
17
  model_idx = 1
 
19
  try:
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):
32
+ output = (model_functions.get(str(idx)) or model_functions.get(str(1)))(prompt)
 
33
  return output
34
  return send_it_fn
35
 
36
  def get_prompts(prompt_text):
37
+
38
  return prompt_text
39
 
40
  def clear_it(val):
41
+ if int(val) != 0:
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
  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)