Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,17 +1,12 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
# import os
|
| 3 |
-
# import sys
|
| 4 |
-
# from pathlib import Path
|
| 5 |
import time
|
| 6 |
|
| 7 |
-
models =[
|
| 8 |
"livingbox/model-test-oct-23-v3",
|
| 9 |
"livingbox/model-test-oct-23-v2",
|
| 10 |
"livingbox/model-test-oct-23",
|
| 11 |
-
|
| 12 |
]
|
| 13 |
|
| 14 |
-
|
| 15 |
model_functions = {}
|
| 16 |
model_idx = 1
|
| 17 |
for model_path in models:
|
|
@@ -21,12 +16,11 @@ for model_path in models:
|
|
| 21 |
def the_fn(txt):
|
| 22 |
return None
|
| 23 |
model_functions[model_idx] = gr.Interface(fn=the_fn, inputs=["text"], outputs=["image"])
|
| 24 |
-
model_idx+=1
|
| 25 |
-
|
| 26 |
|
| 27 |
def send_it_idx(idx):
|
| 28 |
def send_it_fn(prompt):
|
| 29 |
-
output = (model_functions.get(
|
| 30 |
return output
|
| 31 |
return send_it_fn
|
| 32 |
|
|
@@ -38,24 +32,20 @@ def clear_it(val):
|
|
| 38 |
val = 0
|
| 39 |
else:
|
| 40 |
val = 0
|
| 41 |
-
pass
|
| 42 |
return val
|
| 43 |
|
| 44 |
-
def all_task_end(cnt,t_stamp):
|
| 45 |
to = t_stamp + 60
|
| 46 |
et = time.time()
|
| 47 |
if et > to and t_stamp != 0:
|
| 48 |
d = gr.update(value=0)
|
| 49 |
tog = gr.update(value=1)
|
| 50 |
-
#print(f'to: {to} et: {et}')
|
| 51 |
else:
|
| 52 |
if cnt != 0:
|
| 53 |
d = gr.update(value=et)
|
| 54 |
else:
|
| 55 |
d = gr.update(value=0)
|
| 56 |
tog = gr.update(value=0)
|
| 57 |
-
#print (f'passing: to: {to} et: {et}')
|
| 58 |
-
pass
|
| 59 |
return d, tog
|
| 60 |
|
| 61 |
def all_task_start():
|
|
@@ -69,21 +59,15 @@ def clear_fn():
|
|
| 69 |
nn = len(models)
|
| 70 |
return tuple([None, *[None for _ in range(nn)]])
|
| 71 |
|
| 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,15 +75,12 @@ with gr.Blocks(title="SD Models") as my_interface:
|
|
| 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,
|
|
@@ -113,16 +94,10 @@ with gr.Blocks(title="SD Models") as my_interface:
|
|
| 113 |
runs_dict = {}
|
| 114 |
model_idx = 1
|
| 115 |
for model_path in models:
|
| 116 |
-
runs_dict[model_idx] = run.click(
|
| 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,
|
|
@@ -136,4 +111,3 @@ with gr.Blocks(title="SD Models") as my_interface:
|
|
| 136 |
|
| 137 |
my_interface.queue(concurrency_count=600, status_update_rate=1)
|
| 138 |
my_interface.launch(inline=True, show_api=False)
|
| 139 |
-
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
| 2 |
import time
|
| 3 |
|
| 4 |
+
models = [
|
| 5 |
"livingbox/model-test-oct-23-v3",
|
| 6 |
"livingbox/model-test-oct-23-v2",
|
| 7 |
"livingbox/model-test-oct-23",
|
|
|
|
| 8 |
]
|
| 9 |
|
|
|
|
| 10 |
model_functions = {}
|
| 11 |
model_idx = 1
|
| 12 |
for model_path in models:
|
|
|
|
| 16 |
def the_fn(txt):
|
| 17 |
return None
|
| 18 |
model_functions[model_idx] = gr.Interface(fn=the_fn, inputs=["text"], outputs=["image"])
|
| 19 |
+
model_idx += 1
|
|
|
|
| 20 |
|
| 21 |
def send_it_idx(idx):
|
| 22 |
def send_it_fn(prompt):
|
| 23 |
+
output = (model_functions.get(idx) or model_functions.get(1))(prompt)
|
| 24 |
return output
|
| 25 |
return send_it_fn
|
| 26 |
|
|
|
|
| 32 |
val = 0
|
| 33 |
else:
|
| 34 |
val = 0
|
|
|
|
| 35 |
return val
|
| 36 |
|
| 37 |
+
def all_task_end(cnt, t_stamp):
|
| 38 |
to = t_stamp + 60
|
| 39 |
et = time.time()
|
| 40 |
if et > to and t_stamp != 0:
|
| 41 |
d = gr.update(value=0)
|
| 42 |
tog = gr.update(value=1)
|
|
|
|
| 43 |
else:
|
| 44 |
if cnt != 0:
|
| 45 |
d = gr.update(value=et)
|
| 46 |
else:
|
| 47 |
d = gr.update(value=0)
|
| 48 |
tog = gr.update(value=0)
|
|
|
|
|
|
|
| 49 |
return d, tog
|
| 50 |
|
| 51 |
def all_task_start():
|
|
|
|
| 59 |
nn = len(models)
|
| 60 |
return tuple([None, *[None for _ in range(nn)]])
|
| 61 |
|
|
|
|
|
|
|
| 62 |
with gr.Blocks(title="SD Models") as my_interface:
|
| 63 |
with gr.Column(scale=12):
|
|
|
|
|
|
|
| 64 |
with gr.Row():
|
| 65 |
with gr.Row(scale=6):
|
| 66 |
+
primary_prompt = gr.Textbox(label="Prompt", value="")
|
|
|
|
| 67 |
with gr.Row(scale=6):
|
|
|
|
| 68 |
with gr.Row():
|
| 69 |
+
run = gr.Button("Run", variant="primary")
|
| 70 |
+
clear_btn = gr.Button("Clear")
|
| 71 |
with gr.Row():
|
| 72 |
sd_outputs = {}
|
| 73 |
model_idx = 1
|
|
|
|
| 75 |
with gr.Column(scale=3, min_width=320):
|
| 76 |
with gr.Box():
|
| 77 |
sd_outputs[model_idx] = gr.Image(label=model_path)
|
|
|
|
| 78 |
model_idx += 1
|
|
|
|
| 79 |
pass
|
|
|
|
| 80 |
with gr.Row(visible=False):
|
| 81 |
+
start_box = gr.Number(interactive=False)
|
| 82 |
+
end_box = gr.Number(interactive=False)
|
| 83 |
+
tog_box = gr.Textbox(value=0, interactive=False)
|
| 84 |
|
| 85 |
start_box.change(
|
| 86 |
all_task_end,
|
|
|
|
| 94 |
runs_dict = {}
|
| 95 |
model_idx = 1
|
| 96 |
for model_path in models:
|
| 97 |
+
runs_dict[model_idx] = run.click(send_it_idx(model_idx), inputs=[primary_prompt], outputs=[sd_outputs[model_idx]])
|
| 98 |
model_idx += 1
|
|
|
|
| 99 |
pass
|
| 100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
clear_btn.click(
|
| 102 |
clear_fn,
|
| 103 |
None,
|
|
|
|
| 111 |
|
| 112 |
my_interface.queue(concurrency_count=600, status_update_rate=1)
|
| 113 |
my_interface.launch(inline=True, show_api=False)
|
|
|