Spaces:
Paused
Paused
Upload 2 files
Browse files- app.py +12 -30
- fl2basepromptgen.py +3 -3
app.py
CHANGED
|
@@ -1,19 +1,9 @@
|
|
| 1 |
import spaces
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
-
from utils import
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
)
|
| 8 |
-
from tagger import (
|
| 9 |
-
predict_tags_wd,
|
| 10 |
-
convert_danbooru_to_e621_prompt,
|
| 11 |
-
remove_specific_prompt,
|
| 12 |
-
insert_recom_prompt,
|
| 13 |
-
compose_prompt_to_copy,
|
| 14 |
-
translate_prompt,
|
| 15 |
-
select_random_character,
|
| 16 |
-
)
|
| 17 |
from fl2sd3longcap import predict_tags_fl2_sd3
|
| 18 |
from fl2basepromptgen import predict_tags_fl2_base_prompt_gen
|
| 19 |
from fl2flux import predict_tags_fl2_flux
|
|
@@ -39,7 +29,7 @@ def description_ui2():
|
|
| 39 |
[Lamini-Prompt-Enchance](https://huggingface.co/gokaygokay/Lamini-Prompt-Enchance),\
|
| 40 |
[Lamini-Prompt-Enchance-Long](https://huggingface.co/gokaygokay/Lamini-Prompt-Enchance-Long),\
|
| 41 |
[Flux-Prompt-Enhance](https://huggingface.co/gokaygokay/Flux-Prompt-Enhance),\
|
| 42 |
-
MiaoshouAI's [Florence-2-
|
| 43 |
"""
|
| 44 |
)
|
| 45 |
|
|
@@ -55,7 +45,7 @@ def main():
|
|
| 55 |
input_tag_type = gr.Radio(label="Convert tags to", info="danbooru for Animagine, e621 for Pony.", choices=["danbooru", "e621"], value="danbooru")
|
| 56 |
recom_prompt = gr.Radio(label="Insert reccomended prompt", choices=["None", "Animagine", "Pony"], value="None", interactive=True)
|
| 57 |
keep_tags = gr.Radio(label="Remove tags leaving only the following", choices=["body", "dress", "all"], value="all")
|
| 58 |
-
image_algorithms = gr.CheckboxGroup(["Use WD Tagger", "Use Florence-2-SD3-Long-Captioner", "Use Florence-2-
|
| 59 |
generate_from_image_btn = gr.Button(value="GENERATE TAGS FROM IMAGE", size="lg", variant="primary")
|
| 60 |
with gr.Group():
|
| 61 |
with gr.Row():
|
|
@@ -102,14 +92,10 @@ def main():
|
|
| 102 |
predict_tags_fl2_base_prompt_gen,
|
| 103 |
[input_image, input_general, image_algorithms],
|
| 104 |
[input_general],
|
| 105 |
-
).success(
|
| 106 |
-
|
| 107 |
-
).success(
|
| 108 |
-
|
| 109 |
-
).success(
|
| 110 |
-
convert_danbooru_to_e621_prompt, [input_general, input_tag_type], [input_general], queue=False,
|
| 111 |
-
).success(
|
| 112 |
-
insert_recom_prompt, [input_general, dummy_np, recom_prompt], [input_general, dummy_np], queue=False,
|
| 113 |
)
|
| 114 |
copy_input_btn.click(compose_prompt_to_copy, [input_character, input_copyright, input_general], [input_tags_to_copy], queue=False).success(
|
| 115 |
gradio_copy_text, [input_tags_to_copy], js=COPY_ACTION_JS,
|
|
@@ -119,13 +105,9 @@ def main():
|
|
| 119 |
prompt_enhancer,
|
| 120 |
[input_character, input_copyright, input_general, prompt_enhancer_model],
|
| 121 |
[output_text, copy_btn, copy_btn_pony],
|
| 122 |
-
).success(
|
| 123 |
-
|
| 124 |
-
).success(
|
| 125 |
-
insert_recom_prompt, [output_text, dummy_np, recom_animagine], [output_text, dummy_np], queue=False,
|
| 126 |
-
).success(
|
| 127 |
-
insert_recom_prompt, [output_text_pony, dummy_np, recom_pony], [output_text_pony, dummy_np], queue=False,
|
| 128 |
-
)
|
| 129 |
copy_btn.click(gradio_copy_text, [output_text], js=COPY_ACTION_JS)
|
| 130 |
copy_btn_pony.click(gradio_copy_text, [output_text_pony], js=COPY_ACTION_JS)
|
| 131 |
|
|
|
|
| 1 |
import spaces
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
+
from utils import gradio_copy_text, COPY_ACTION_JS
|
| 5 |
+
from tagger import (predict_tags_wd, convert_danbooru_to_e621_prompt, remove_specific_prompt,
|
| 6 |
+
insert_recom_prompt, compose_prompt_to_copy, translate_prompt, select_random_character)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
from fl2sd3longcap import predict_tags_fl2_sd3
|
| 8 |
from fl2basepromptgen import predict_tags_fl2_base_prompt_gen
|
| 9 |
from fl2flux import predict_tags_fl2_flux
|
|
|
|
| 29 |
[Lamini-Prompt-Enchance](https://huggingface.co/gokaygokay/Lamini-Prompt-Enchance),\
|
| 30 |
[Lamini-Prompt-Enchance-Long](https://huggingface.co/gokaygokay/Lamini-Prompt-Enchance-Long),\
|
| 31 |
[Flux-Prompt-Enhance](https://huggingface.co/gokaygokay/Flux-Prompt-Enhance),\
|
| 32 |
+
MiaoshouAI's [Florence-2-large-PromptGen-v1.5](https://huggingface.co/MiaoshouAI/Florence-2-large-PromptGen-v1.5).
|
| 33 |
"""
|
| 34 |
)
|
| 35 |
|
|
|
|
| 45 |
input_tag_type = gr.Radio(label="Convert tags to", info="danbooru for Animagine, e621 for Pony.", choices=["danbooru", "e621"], value="danbooru")
|
| 46 |
recom_prompt = gr.Radio(label="Insert reccomended prompt", choices=["None", "Animagine", "Pony"], value="None", interactive=True)
|
| 47 |
keep_tags = gr.Radio(label="Remove tags leaving only the following", choices=["body", "dress", "all"], value="all")
|
| 48 |
+
image_algorithms = gr.CheckboxGroup(["Use WD Tagger", "Use Florence-2-SD3-Long-Captioner", "Use Florence-2-Flux", "Use Florence-2-Flux-Large", "Use Florence-2-large-PromptGen"], label="Algorithms", value=["Use WD Tagger", "Use Florence-2-Flux"])
|
| 49 |
generate_from_image_btn = gr.Button(value="GENERATE TAGS FROM IMAGE", size="lg", variant="primary")
|
| 50 |
with gr.Group():
|
| 51 |
with gr.Row():
|
|
|
|
| 92 |
predict_tags_fl2_base_prompt_gen,
|
| 93 |
[input_image, input_general, image_algorithms],
|
| 94 |
[input_general],
|
| 95 |
+
).success(predict_tags_fl2_flux, [input_image, input_general, image_algorithms], [input_general],
|
| 96 |
+
).success(remove_specific_prompt, [input_general, keep_tags], [input_general], queue=False,
|
| 97 |
+
).success(convert_danbooru_to_e621_prompt, [input_general, input_tag_type], [input_general], queue=False,
|
| 98 |
+
).success(insert_recom_prompt, [input_general, dummy_np, recom_prompt], [input_general, dummy_np], queue=False,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
)
|
| 100 |
copy_input_btn.click(compose_prompt_to_copy, [input_character, input_copyright, input_general], [input_tags_to_copy], queue=False).success(
|
| 101 |
gradio_copy_text, [input_tags_to_copy], js=COPY_ACTION_JS,
|
|
|
|
| 105 |
prompt_enhancer,
|
| 106 |
[input_character, input_copyright, input_general, prompt_enhancer_model],
|
| 107 |
[output_text, copy_btn, copy_btn_pony],
|
| 108 |
+
).success(convert_danbooru_to_e621_prompt, [output_text, tag_type], [output_text_pony], queue=False,
|
| 109 |
+
).success(insert_recom_prompt, [output_text, dummy_np, recom_animagine], [output_text, dummy_np], queue=False,
|
| 110 |
+
).success(insert_recom_prompt, [output_text_pony, dummy_np, recom_pony], [output_text_pony, dummy_np], queue=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
copy_btn.click(gradio_copy_text, [output_text], js=COPY_ACTION_JS)
|
| 112 |
copy_btn_pony.click(gradio_copy_text, [output_text_pony], js=COPY_ACTION_JS)
|
| 113 |
|
fl2basepromptgen.py
CHANGED
|
@@ -9,8 +9,8 @@ subprocess.run('pip install flash-attn --no-build-isolation', env={'FLASH_ATTENT
|
|
| 9 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 10 |
|
| 11 |
try:
|
| 12 |
-
fl_model = AutoModelForCausalLM.from_pretrained('MiaoshouAI/Florence-2-
|
| 13 |
-
fl_processor = AutoProcessor.from_pretrained('MiaoshouAI/Florence-2-
|
| 14 |
except Exception as e:
|
| 15 |
print(e)
|
| 16 |
fl_model = fl_processor = None
|
|
@@ -46,7 +46,7 @@ def predict_tags_fl2_base_prompt_gen(image: Image.Image, input_tags: str, algo:
|
|
| 46 |
def list_uniq(l):
|
| 47 |
return sorted(set(l), key=l.index)
|
| 48 |
|
| 49 |
-
if not "Use Florence-2-
|
| 50 |
return input_tags
|
| 51 |
tag_list = list_uniq(to_list(input_tags) + to_list(fl_run(image) + ", "))
|
| 52 |
tag_list.remove("")
|
|
|
|
| 9 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 10 |
|
| 11 |
try:
|
| 12 |
+
fl_model = AutoModelForCausalLM.from_pretrained('MiaoshouAI/Florence-2-large-PromptGen-v1.5', trust_remote_code=True).to("cpu").eval()
|
| 13 |
+
fl_processor = AutoProcessor.from_pretrained('MiaoshouAI/Florence-2-large-PromptGen-v1.5', trust_remote_code=True)
|
| 14 |
except Exception as e:
|
| 15 |
print(e)
|
| 16 |
fl_model = fl_processor = None
|
|
|
|
| 46 |
def list_uniq(l):
|
| 47 |
return sorted(set(l), key=l.index)
|
| 48 |
|
| 49 |
+
if not "Use Florence-2-large-PromptGen" in algo:
|
| 50 |
return input_tags
|
| 51 |
tag_list = list_uniq(to_list(input_tags) + to_list(fl_run(image) + ", "))
|
| 52 |
tag_list.remove("")
|