Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,140 +1,29 @@
|
|
1 |
import gradio as gr
|
2 |
-
# import os
|
3 |
-
# import sys
|
4 |
-
# from pathlib import Path
|
5 |
-
import time
|
6 |
|
7 |
-
models =[
|
8 |
-
"enhanceaiteam/Flux-uncensored",
|
9 |
-
"CultriX/flux-nsfw-highress",
|
10 |
-
"pimpilikipilapi1/NSFW_master",
|
11 |
-
"DiegoJR1973/NSFW-TrioHMH-Flux",
|
12 |
-
"lustlyai/Flux_Lustly.ai_Uncensored_nsfw_v1",
|
13 |
-
"prashanth970/flux-lora-uncensored",
|
14 |
-
"black-forest-labs/FLUX.1-dev",
|
15 |
-
]
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
except Exception as error:
|
23 |
-
def the_fn(txt):
|
24 |
-
return None
|
25 |
-
model_functions[model_idx] = gr.Interface(fn=the_fn, inputs=["text"], outputs=["image"])
|
26 |
-
model_idx+=1
|
27 |
|
28 |
|
29 |
-
def
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
return
|
34 |
|
35 |
-
def get_prompts(prompt_text):
|
36 |
-
return prompt_text
|
37 |
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
|
|
|
|
|
|
45 |
|
46 |
-
|
47 |
-
to = t_stamp + 360
|
48 |
-
et = time.time()
|
49 |
-
if et > to and t_stamp != 0:
|
50 |
-
d = gr.update(value=0)
|
51 |
-
tog = gr.update(value=1)
|
52 |
-
#print(f'to: {to} et: {et}')
|
53 |
-
else:
|
54 |
-
if cnt != 0:
|
55 |
-
d = gr.update(value=et)
|
56 |
-
else:
|
57 |
-
d = gr.update(value=0)
|
58 |
-
tog = gr.update(value=0)
|
59 |
-
#print (f'passing: to: {to} et: {et}')
|
60 |
-
pass
|
61 |
-
return d, tog
|
62 |
-
|
63 |
-
def all_task_start():
|
64 |
-
print("\n\n\n\n\n\n\n")
|
65 |
-
t = time.gmtime()
|
66 |
-
t_stamp = time.time()
|
67 |
-
current_time = time.strftime("%H:%M:%S", t)
|
68 |
-
return gr.update(value=t_stamp), gr.update(value=t_stamp), gr.update(value=0)
|
69 |
-
|
70 |
-
def clear_fn():
|
71 |
-
nn = len(models)
|
72 |
-
return tuple([None, *[None for _ in range(nn)]])
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
with gr.Blocks(title="SD Models") as my_interface:
|
77 |
-
with gr.Column(scale=12):
|
78 |
-
# with gr.Row():
|
79 |
-
# gr.Markdown("""- Primary prompt: 你想画的内容(英文单词,如 a cat, 加英文逗号效果更好;点 Improve 按钮进行完善)\n- Real prompt: 完善后的提示词,出现后再点右边的 Run 按钮开始运行""")
|
80 |
-
with gr.Row():
|
81 |
-
with gr.Row(scale=6):
|
82 |
-
primary_prompt=gr.Textbox(label="Prompt", value="")
|
83 |
-
# real_prompt=gr.Textbox(label="Real prompt")
|
84 |
-
with gr.Row(scale=6):
|
85 |
-
# improve_prompts_btn=gr.Button("Improve")
|
86 |
-
with gr.Row():
|
87 |
-
run=gr.Button("Run",variant="primary")
|
88 |
-
clear_btn=gr.Button("Clear")
|
89 |
-
with gr.Row():
|
90 |
-
sd_outputs = {}
|
91 |
-
model_idx = 1
|
92 |
-
for model_path in models:
|
93 |
-
with gr.Column(scale=3, min_width=200):
|
94 |
-
with gr.Box():
|
95 |
-
sd_outputs[model_idx] = gr.Image(label=model_path)
|
96 |
-
pass
|
97 |
-
model_idx += 1
|
98 |
-
pass
|
99 |
-
pass
|
100 |
-
|
101 |
-
with gr.Row(visible=False):
|
102 |
-
start_box=gr.Number(interactive=False)
|
103 |
-
end_box=gr.Number(interactive=False)
|
104 |
-
tog_box=gr.Textbox(value=0,interactive=False)
|
105 |
-
|
106 |
-
start_box.change(
|
107 |
-
all_task_end,
|
108 |
-
[start_box, end_box],
|
109 |
-
[start_box, tog_box],
|
110 |
-
every=1,
|
111 |
-
show_progress=True)
|
112 |
-
|
113 |
-
primary_prompt.submit(all_task_start, None, [start_box, end_box, tog_box])
|
114 |
-
run.click(all_task_start, None, [start_box, end_box, tog_box])
|
115 |
-
runs_dict = {}
|
116 |
-
model_idx = 1
|
117 |
-
for model_path in models:
|
118 |
-
runs_dict[model_idx] = run.click(model_functions[model_idx], inputs=[primary_prompt], outputs=[sd_outputs[model_idx]])
|
119 |
-
model_idx += 1
|
120 |
-
pass
|
121 |
-
pass
|
122 |
-
|
123 |
-
# improve_prompts_btn_clicked=improve_prompts_btn.click(
|
124 |
-
# get_prompts,
|
125 |
-
# inputs=[primary_prompt],
|
126 |
-
# outputs=[primary_prompt],
|
127 |
-
# cancels=list(runs_dict.values()))
|
128 |
-
clear_btn.click(
|
129 |
-
clear_fn,
|
130 |
-
None,
|
131 |
-
[primary_prompt, *list(sd_outputs.values())],
|
132 |
-
cancels=[*list(runs_dict.values())])
|
133 |
-
tog_box.change(
|
134 |
-
clear_it,
|
135 |
-
tog_box,
|
136 |
-
tog_box,
|
137 |
-
cancels=[*list(runs_dict.values())])
|
138 |
-
|
139 |
-
my_interface.queue(concurrency_count=100, status_update_rate=1)
|
140 |
-
my_interface.launch(inline=True, show_api=False)
|
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
+
models = {
|
5 |
+
"Flux Lora": "models/prashanth970/flux-lora-uncensored",
|
6 |
+
"TrioHMH Flux": "models/DiegoJR1973/NSFW-TrioHMH-Flux",
|
7 |
+
"Master": "models/pimpilikipilapi1/NSFW_master"
|
8 |
+
}
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
|
11 |
+
def generate_image(text, model_name):
|
12 |
+
model_path = models[model_name]
|
13 |
+
model = gr.load(model_path)
|
14 |
+
result_image = model(text)
|
15 |
+
return result_image
|
16 |
|
|
|
|
|
17 |
|
18 |
+
interface = gr.Interface(
|
19 |
+
fn=generate_image,
|
20 |
+
inputs=[
|
21 |
+
gr.Textbox(label="Type here your imagination:", placeholder="Type your description here..."),
|
22 |
+
gr.Dropdown(label="Select Model", choices=list(models.keys()), type="value", default="Flux Lora")
|
23 |
+
],
|
24 |
+
outputs=gr.Image(label="Generated Image"),
|
25 |
+
theme="NoCrypt/miku",
|
26 |
+
description="Sorry for the inconvenience. The model is currently running on the CPU, which might affect performance. We appreciate your understanding.",
|
27 |
+
)
|
28 |
|
29 |
+
interface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|