Pamudu13 commited on
Commit
e6db718
1 Parent(s): 180b8b5

Update app.py

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