Spaces:
Running
Running
miaowm5 commited on
Commit ·
c43f64e
1
Parent(s): df7df8f
update logic
Browse files- app.py +25 -13
- checkIgnore.py +4 -2
- createTagDom.py +0 -20
- head.html +1 -1
- requirements.txt +3 -3
app.py
CHANGED
|
@@ -6,18 +6,11 @@ import gradio as gr
|
|
| 6 |
import PIL.Image
|
| 7 |
import zipfile
|
| 8 |
from genTag import genTag
|
| 9 |
-
from checkIgnore import is_ignore
|
| 10 |
-
from createTagDom import create_tag_dom
|
| 11 |
|
| 12 |
def predict(image: PIL.Image.Image):
|
| 13 |
result_threshold = genTag(image, 0.5)
|
| 14 |
-
|
| 15 |
-
for label, prob in result_threshold.items():
|
| 16 |
-
result_html += create_tag_dom(label, is_ignore(label, 1), prob)
|
| 17 |
-
result_html = '<div>' + result_html + '</div>'
|
| 18 |
-
result_filter = {key: value for key, value in result_threshold.items() if not is_ignore(key, 1)}
|
| 19 |
-
result_text = '<div id="m5dd_result">' + ', '.join(result_filter.keys()) + '</div>'
|
| 20 |
-
return result_html, result_text
|
| 21 |
|
| 22 |
def predict_api(image: PIL.Image.Image):
|
| 23 |
result_threshold = genTag(image, 0.5)
|
|
@@ -50,9 +43,12 @@ with gr.Blocks(head_paths="head.html") as demo:
|
|
| 50 |
image_mode="RGBA",
|
| 51 |
show_fullscreen_button=False,
|
| 52 |
sources=["upload", "clipboard"])
|
| 53 |
-
result_text = gr.HTML(value="", elem_classes='m5dd_html', padding=False)
|
|
|
|
|
|
|
| 54 |
with gr.Column(scale=2):
|
| 55 |
-
result_html = gr.HTML(value="", elem_classes='m5dd_html', padding=False)
|
|
|
|
| 56 |
with gr.Tab(label='Batch'):
|
| 57 |
with gr.Row():
|
| 58 |
with gr.Column(scale=1):
|
|
@@ -69,9 +65,25 @@ with gr.Blocks(head_paths="head.html") as demo:
|
|
| 69 |
image.upload(
|
| 70 |
fn=predict,
|
| 71 |
inputs=[image],
|
| 72 |
-
outputs=[
|
| 73 |
api_name=False,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
)
|
|
|
|
| 75 |
run_button2.click(
|
| 76 |
fn=predict_batch,
|
| 77 |
inputs=[batch_file],
|
|
@@ -86,4 +98,4 @@ with gr.Blocks(head_paths="head.html") as demo:
|
|
| 86 |
)
|
| 87 |
|
| 88 |
if __name__ == "__main__":
|
| 89 |
-
demo.queue(max_size=20).launch()
|
|
|
|
| 6 |
import PIL.Image
|
| 7 |
import zipfile
|
| 8 |
from genTag import genTag
|
| 9 |
+
from checkIgnore import is_ignore, ignore2
|
|
|
|
| 10 |
|
| 11 |
def predict(image: PIL.Image.Image):
|
| 12 |
result_threshold = genTag(image, 0.5)
|
| 13 |
+
return result_threshold, ignore2, """<div></div>"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
def predict_api(image: PIL.Image.Image):
|
| 16 |
result_threshold = genTag(image, 0.5)
|
|
|
|
| 43 |
image_mode="RGBA",
|
| 44 |
show_fullscreen_button=False,
|
| 45 |
sources=["upload", "clipboard"])
|
| 46 |
+
result_text = gr.HTML(value="""<div id="m5dd_result"></div>""", elem_classes='m5dd_html', padding=False)
|
| 47 |
+
result_hide = gr.JSON(visible=False)
|
| 48 |
+
result_hide2 = gr.JSON(visible=False)
|
| 49 |
with gr.Column(scale=2):
|
| 50 |
+
result_html = gr.HTML(value="""<div id="m5dd_list"></div>""", elem_classes='m5dd_html', padding=False)
|
| 51 |
+
result_loading = gr.HTML(value="""<div></div>""", elem_classes='m5dd_html', padding=False)
|
| 52 |
with gr.Tab(label='Batch'):
|
| 53 |
with gr.Row():
|
| 54 |
with gr.Column(scale=1):
|
|
|
|
| 65 |
image.upload(
|
| 66 |
fn=predict,
|
| 67 |
inputs=[image],
|
| 68 |
+
outputs=[result_hide, result_hide2, result_loading],
|
| 69 |
api_name=False,
|
| 70 |
+
js="""
|
| 71 |
+
(image) => {
|
| 72 |
+
window.m5Func.clear()
|
| 73 |
+
return image;
|
| 74 |
+
}
|
| 75 |
+
""",
|
| 76 |
+
).success(
|
| 77 |
+
fn=None,
|
| 78 |
+
inputs=[result_hide, result_hide2],
|
| 79 |
+
js="""
|
| 80 |
+
(result, ignore) => {
|
| 81 |
+
window.m5Func.refresh(result, ignore)
|
| 82 |
+
return [result, ignore];
|
| 83 |
+
}
|
| 84 |
+
""",
|
| 85 |
)
|
| 86 |
+
|
| 87 |
run_button2.click(
|
| 88 |
fn=predict_batch,
|
| 89 |
inputs=[batch_file],
|
|
|
|
| 98 |
)
|
| 99 |
|
| 100 |
if __name__ == "__main__":
|
| 101 |
+
demo.queue(max_size=20).launch()
|
checkIgnore.py
CHANGED
|
@@ -13,10 +13,12 @@ def load_ignore(file_path):
|
|
| 13 |
return result_dict
|
| 14 |
|
| 15 |
ignore1 = load_ignore('ignoreTag.txt')
|
| 16 |
-
|
|
|
|
|
|
|
| 17 |
|
| 18 |
def is_ignore(tag, ignore_type):
|
| 19 |
if ignore_type == 1:
|
| 20 |
-
return tag in
|
| 21 |
elif ignore_type == 2:
|
| 22 |
return tag in ignore1
|
|
|
|
| 13 |
return result_dict
|
| 14 |
|
| 15 |
ignore1 = load_ignore('ignoreTag.txt')
|
| 16 |
+
ignore_extra = load_ignore('ignoreTag2.txt')
|
| 17 |
+
ignore2 = ignore1.copy()
|
| 18 |
+
ignore2.update(ignore_extra)
|
| 19 |
|
| 20 |
def is_ignore(tag, ignore_type):
|
| 21 |
if ignore_type == 1:
|
| 22 |
+
return tag in ignore2
|
| 23 |
elif ignore_type == 2:
|
| 24 |
return tag in ignore1
|
createTagDom.py
DELETED
|
@@ -1,20 +0,0 @@
|
|
| 1 |
-
#!/usr/bin/env python
|
| 2 |
-
|
| 3 |
-
from __future__ import annotations
|
| 4 |
-
|
| 5 |
-
def create_tag_dom(label, ignore, prob):
|
| 6 |
-
result_html = ''
|
| 7 |
-
if ignore:
|
| 8 |
-
result_html += '<div class="m5dd_list">'
|
| 9 |
-
else:
|
| 10 |
-
result_html += '<div class="m5dd_list use">'
|
| 11 |
-
result_html += '<span class="add action">➕</span>'
|
| 12 |
-
result_html += '<span class="dec action">➖</span>'
|
| 13 |
-
result_html += '<span class="label action">' + str(label) + '</span>'
|
| 14 |
-
result_html += '<span class="prob">' + str(round(prob, 3)) + '</span>'
|
| 15 |
-
result_html += '<span class="up action">🔼</span>'
|
| 16 |
-
result_html += '<span class="down action">🔽</span>'
|
| 17 |
-
result_html += '<a class="wiki action" href="https://danbooru.donmai.us/wiki_pages/' + label + '" target="_blank">📙</a>'
|
| 18 |
-
result_html += '</div>'
|
| 19 |
-
|
| 20 |
-
return result_html
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
head.html
CHANGED
|
@@ -1,2 +1,2 @@
|
|
| 1 |
<link rel="stylesheet" href="https://cdn.miaowm5.com/neet/deepdanbooru/styles.css" />
|
| 2 |
-
<script src="https://cdn.miaowm5.com/neet/deepdanbooru/scripts.js"
|
|
|
|
| 1 |
<link rel="stylesheet" href="https://cdn.miaowm5.com/neet/deepdanbooru/styles.css" />
|
| 2 |
+
<script src="https://cdn.miaowm5.com/neet/deepdanbooru/scripts.js?2601211925"></script>
|
requirements.txt
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
pillow
|
| 2 |
-
tensorflow
|
| 3 |
-
onnxruntime
|
| 4 |
huggingface-hub
|
|
|
|
| 1 |
+
pillow
|
| 2 |
+
tensorflow
|
| 3 |
+
onnxruntime
|
| 4 |
huggingface-hub
|