Pamudu13 commited on
Commit
7e8dfc1
·
verified ·
1 Parent(s): 1d44b13

Update app.py

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