Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -2,61 +2,122 @@ import gradio as gr
|
|
2 |
import time
|
3 |
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
-
models = {
|
10 |
-
1: model1,
|
11 |
-
2: model2,
|
12 |
-
3: model3
|
13 |
-
}
|
14 |
|
15 |
def send_it_idx(idx):
|
16 |
def send_it_fn(prompt):
|
17 |
-
|
18 |
-
|
19 |
-
return model(prompt)
|
20 |
-
return None
|
21 |
return send_it_fn
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
def clear_fn():
|
24 |
-
|
|
|
|
|
|
|
25 |
|
26 |
with gr.Blocks(title="SD Models") as my_interface:
|
27 |
with gr.Column(scale=12):
|
28 |
with gr.Row():
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
with gr.Row(visible=False):
|
41 |
-
start_box
|
42 |
-
end_box
|
43 |
-
tog_box
|
44 |
|
45 |
-
|
46 |
-
|
47 |
-
|
|
|
|
|
|
|
48 |
|
49 |
primary_prompt.submit(all_task_start, None, [start_box, end_box, tog_box])
|
50 |
run.click(all_task_start, None, [start_box, end_box, tog_box])
|
51 |
-
|
52 |
-
|
53 |
-
|
|
|
|
|
|
|
|
|
54 |
|
55 |
clear_btn.click(
|
56 |
clear_fn,
|
57 |
None,
|
58 |
-
[primary_prompt, *list(sd_outputs.values())]
|
59 |
-
|
|
|
|
|
|
|
|
|
|
|
60 |
|
61 |
my_interface.queue(concurrency_count=100, status_update_rate=1)
|
62 |
-
my_interface.launch(inline=True, show_api=False)
|
|
|
2 |
import time
|
3 |
|
4 |
|
5 |
+
models =[
|
6 |
+
"pimpilikipilapi1/NSFW_master",
|
7 |
+
"DiegoJR1973/NSFW-TrioHMH-Flux",
|
8 |
+
"prashanth970/flux-lora-uncensored",
|
9 |
+
]
|
10 |
+
|
11 |
+
model_functions = {}
|
12 |
+
model_idx = 1
|
13 |
+
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):
|
18 |
+
return None
|
19 |
+
model_functions[model_idx] = gr.Interface(fn=the_fn, inputs=["text"], outputs=["image"])
|
20 |
+
model_idx+=1
|
21 |
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
def send_it_idx(idx):
|
24 |
def send_it_fn(prompt):
|
25 |
+
output = (model_functions.get(str(idx)) or model_functions.get(str(1)))(prompt)
|
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 |
+
if int(val) != 0:
|
34 |
+
val = 0
|
35 |
+
else:
|
36 |
+
val = 0
|
37 |
+
pass
|
38 |
+
return val
|
39 |
+
|
40 |
+
def all_task_end(cnt,t_stamp):
|
41 |
+
to = t_stamp + 360
|
42 |
+
et = time.time()
|
43 |
+
if et > to and t_stamp != 0:
|
44 |
+
d = gr.update(value=0)
|
45 |
+
tog = gr.update(value=1)
|
46 |
+
else:
|
47 |
+
if cnt != 0:
|
48 |
+
d = gr.update(value=et)
|
49 |
+
else:
|
50 |
+
d = gr.update(value=0)
|
51 |
+
tog = gr.update(value=0)
|
52 |
+
pass
|
53 |
+
return d, tog
|
54 |
+
|
55 |
+
def all_task_start():
|
56 |
+
print("\n\n\n\n\n\n\n")
|
57 |
+
t = time.gmtime()
|
58 |
+
t_stamp = time.time()
|
59 |
+
current_time = time.strftime("%H:%M:%S", t)
|
60 |
+
return gr.update(value=t_stamp), gr.update(value=t_stamp), gr.update(value=0)
|
61 |
+
|
62 |
def clear_fn():
|
63 |
+
nn = len(models)
|
64 |
+
return tuple([None, *[None for _ in range(nn)]])
|
65 |
+
|
66 |
+
|
67 |
|
68 |
with gr.Blocks(title="SD Models") as my_interface:
|
69 |
with gr.Column(scale=12):
|
70 |
with gr.Row():
|
71 |
+
with gr.Row(scale=6):
|
72 |
+
primary_prompt=gr.Textbox(label="Prompt", value="")
|
73 |
+
with gr.Row(scale=6):
|
74 |
+
with gr.Row():
|
75 |
+
run=gr.Button("Run",variant="primary")
|
76 |
+
clear_btn=gr.Button("Clear")
|
77 |
+
with gr.Row():
|
78 |
+
sd_outputs = {}
|
79 |
+
model_idx = 1
|
80 |
+
for model_path in models:
|
81 |
+
with gr.Column(scale=3, min_width=200):
|
82 |
+
with gr.Box():
|
83 |
+
sd_outputs[model_idx] = gr.Image(label=model_path)
|
84 |
+
pass
|
85 |
+
model_idx += 1
|
86 |
+
pass
|
87 |
+
pass
|
88 |
|
89 |
with gr.Row(visible=False):
|
90 |
+
start_box=gr.Number(interactive=False)
|
91 |
+
end_box=gr.Number(interactive=False)
|
92 |
+
tog_box=gr.Textbox(value=0,interactive=False)
|
93 |
|
94 |
+
start_box.change(
|
95 |
+
all_task_end,
|
96 |
+
[start_box, end_box],
|
97 |
+
[start_box, tog_box],
|
98 |
+
every=1,
|
99 |
+
show_progress=True)
|
100 |
|
101 |
primary_prompt.submit(all_task_start, None, [start_box, end_box, tog_box])
|
102 |
run.click(all_task_start, None, [start_box, end_box, tog_box])
|
103 |
+
runs_dict = {}
|
104 |
+
model_idx = 1
|
105 |
+
for model_path in models:
|
106 |
+
runs_dict[model_idx] = run.click(model_functions[model_idx], inputs=[primary_prompt], outputs=[sd_outputs[model_idx]])
|
107 |
+
model_idx += 1
|
108 |
+
pass
|
109 |
+
pass
|
110 |
|
111 |
clear_btn.click(
|
112 |
clear_fn,
|
113 |
None,
|
114 |
+
[primary_prompt, *list(sd_outputs.values())],
|
115 |
+
cancels=[*list(runs_dict.values())])
|
116 |
+
tog_box.change(
|
117 |
+
clear_it,
|
118 |
+
tog_box,
|
119 |
+
tog_box,
|
120 |
+
cancels=[*list(runs_dict.values())])
|
121 |
|
122 |
my_interface.queue(concurrency_count=100, status_update_rate=1)
|
123 |
+
my_interface.launch(inline=True, show_api=False)
|