Spaces:
Running
Running
Commit
·
895ccaa
1
Parent(s):
935457c
create button dom
Browse files
app.py
CHANGED
@@ -7,16 +7,13 @@ import PIL.Image
|
|
7 |
import zipfile
|
8 |
from genTag import genTag
|
9 |
from checkIgnore import is_ignore
|
|
|
10 |
|
11 |
def predict(image: PIL.Image.Image, score_threshold: float):
|
12 |
result_threshold = genTag(image, score_threshold)
|
13 |
result_html = ''
|
14 |
for label, prob in result_threshold.items():
|
15 |
-
|
16 |
-
result_html += '<p class="m5dd_list">'
|
17 |
-
else:
|
18 |
-
result_html += '<p class="m5dd_list use">'
|
19 |
-
result_html = result_html + '<span>' + str(label) + '</span><span>' + str(round(prob, 3)) + '</span></p>'
|
20 |
result_html = '<div>' + result_html + '</div>'
|
21 |
result_filter = {key: value for key, value in result_threshold.items() if not is_ignore(key, 1)}
|
22 |
result_text = '<div id="m5dd_result">' + ', '.join(result_filter.keys()) + '</div>'
|
|
|
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, score_threshold: float):
|
13 |
result_threshold = genTag(image, score_threshold)
|
14 |
result_html = ''
|
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>'
|
createTagDom.py
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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="up action">🔼</span>'
|
12 |
+
result_html += '<span class="down 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 += '<a class="wiki action" href="https://danbooru.donmai.us/wiki_pages/' + label + '" target="_blank">📙</a>'
|
16 |
+
result_html += '<span class="add action">➕</span>'
|
17 |
+
result_html += '<span class="dec action">➖</span>'
|
18 |
+
result_html += '</div>'
|
19 |
+
|
20 |
+
return result_html
|
script.js
CHANGED
@@ -4,15 +4,36 @@ async () => {
|
|
4 |
let tagItem = event.target.closest('.m5dd_list')
|
5 |
let resultArea = event.target.closest('#m5dd_result')
|
6 |
if (tagItem) {
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
}
|
12 |
-
document.getElementById('m5dd_result').innerText =
|
13 |
-
Array.from(document.querySelectorAll('.m5dd_list.use>span:nth-child(1)'))
|
14 |
-
.map(v => v.innerText)
|
15 |
-
.join(', ')
|
16 |
} else if (resultArea) {
|
17 |
const selection = window.getSelection()
|
18 |
selection.removeAllRanges()
|
|
|
4 |
let tagItem = event.target.closest('.m5dd_list')
|
5 |
let resultArea = event.target.closest('#m5dd_result')
|
6 |
if (tagItem) {
|
7 |
+
let labelItem = event.target.closest('span.label')
|
8 |
+
let upItem = event.target.closest('span.up')
|
9 |
+
let downItem = event.target.closest('span.down')
|
10 |
+
let addItem = event.target.closest('span.add')
|
11 |
+
let decItem = event.target.closest('span.dec')
|
12 |
+
let actionItem = event.target.closest('span.action')
|
13 |
+
if (labelItem) {
|
14 |
+
if (tagItem.classList.contains('use')) {
|
15 |
+
tagItem.classList.remove('use')
|
16 |
+
} else {
|
17 |
+
tagItem.classList.add('use')
|
18 |
+
}
|
19 |
+
}
|
20 |
+
if (upItem) { }
|
21 |
+
if (downItem) { }
|
22 |
+
if (addItem) {
|
23 |
+
let label = tagItem.querySelector('span.label').innerText
|
24 |
+
tagItem.querySelector('span.label').innerText = `(${label})`
|
25 |
+
}
|
26 |
+
if (decItem) {
|
27 |
+
let label = tagItem.querySelector('span.label').innerText
|
28 |
+
label = label.replace(/^\s*\(\s*(.+?)\s*\)\s*$/, '$1')
|
29 |
+
tagItem.querySelector('span.label').innerText = label
|
30 |
+
}
|
31 |
+
if (actionItem) {
|
32 |
+
document.getElementById('m5dd_result').innerText =
|
33 |
+
Array.from(document.querySelectorAll('.m5dd_list.use>span.label'))
|
34 |
+
.map(v => v.innerText)
|
35 |
+
.join(', ')
|
36 |
}
|
|
|
|
|
|
|
|
|
37 |
} else if (resultArea) {
|
38 |
const selection = window.getSelection()
|
39 |
selection.removeAllRanges()
|
style.css
CHANGED
@@ -5,11 +5,11 @@
|
|
5 |
padding: 0.2em 0.5em;
|
6 |
}
|
7 |
|
8 |
-
.m5dd_list>span
|
9 |
flex: 1;
|
10 |
}
|
11 |
|
12 |
-
.m5dd_list>span
|
13 |
color: #aaa;
|
14 |
}
|
15 |
|
@@ -17,7 +17,7 @@
|
|
17 |
background: #ecedf0;
|
18 |
}
|
19 |
|
20 |
-
.m5dd_list:not(.use)>span {
|
21 |
text-decoration: line-through;
|
22 |
color: #ccc;
|
23 |
}
|
|
|
5 |
padding: 0.2em 0.5em;
|
6 |
}
|
7 |
|
8 |
+
.m5dd_list>span.label {
|
9 |
flex: 1;
|
10 |
}
|
11 |
|
12 |
+
.m5dd_list>span.prob {
|
13 |
color: #aaa;
|
14 |
}
|
15 |
|
|
|
17 |
background: #ecedf0;
|
18 |
}
|
19 |
|
20 |
+
.m5dd_list:not(.use)>span.label {
|
21 |
text-decoration: line-through;
|
22 |
color: #ccc;
|
23 |
}
|