Spaces:
Running
Running
MonkeyJuice
commited on
Commit
•
c410097
1
Parent(s):
aa7c58e
check ignore
Browse files- app.py +14 -6
- checkIgnore.py +22 -0
app.py
CHANGED
@@ -6,15 +6,20 @@ import gradio as gr
|
|
6 |
import PIL.Image
|
7 |
import zipfile
|
8 |
from genTag import genTag
|
|
|
9 |
|
10 |
def predict(image: PIL.Image.Image, score_threshold: float):
|
11 |
result_threshold = genTag(image, score_threshold)
|
12 |
result_html = ''
|
13 |
for label, prob in result_threshold.items():
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
18 |
return result_html, result_text
|
19 |
|
20 |
def predict_batch(zip_file, score_threshold: float, progress=gr.Progress()):
|
@@ -27,7 +32,8 @@ def predict_batch(zip_file, score_threshold: float, progress=gr.Progress()):
|
|
27 |
image = PIL.Image.open(image_file)
|
28 |
image = image.convert("RGB")
|
29 |
result_threshold = genTag(image, score_threshold)
|
30 |
-
|
|
|
31 |
result = result + str(file) + '\n' + str(tag) + '\n'
|
32 |
return result
|
33 |
|
@@ -61,7 +67,9 @@ with gr.Blocks(css="style.css", js="script.js") as demo:
|
|
61 |
value=0.5)
|
62 |
run_button2 = gr.Button('Run')
|
63 |
with gr.Column(scale=2):
|
64 |
-
result_text2 = gr.Textbox(lines=5,
|
|
|
|
|
65 |
|
66 |
run_button.click(
|
67 |
fn=predict,
|
|
|
6 |
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 |
+
if is_ignore(label, 1):
|
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>'
|
23 |
return result_html, result_text
|
24 |
|
25 |
def predict_batch(zip_file, score_threshold: float, progress=gr.Progress()):
|
|
|
32 |
image = PIL.Image.open(image_file)
|
33 |
image = image.convert("RGB")
|
34 |
result_threshold = genTag(image, score_threshold)
|
35 |
+
result_filter = {key: value for key, value in result_threshold.items() if not is_ignore(key, 2)}
|
36 |
+
tag = ', '.join(result_filter.keys())
|
37 |
result = result + str(file) + '\n' + str(tag) + '\n'
|
38 |
return result
|
39 |
|
|
|
67 |
value=0.5)
|
68 |
run_button2 = gr.Button('Run')
|
69 |
with gr.Column(scale=2):
|
70 |
+
result_text2 = gr.Textbox(lines=5,
|
71 |
+
label='Result',
|
72 |
+
show_copy_button=True)
|
73 |
|
74 |
run_button.click(
|
75 |
fn=predict,
|
checkIgnore.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
|
3 |
+
from __future__ import annotations
|
4 |
+
|
5 |
+
def load_ignore(file_path):
|
6 |
+
result_dict = {}
|
7 |
+
with open(file_path, 'r') as file:
|
8 |
+
for line in file:
|
9 |
+
line = line.strip()
|
10 |
+
if line:
|
11 |
+
line_without_trailing_comma = line.rstrip(',')
|
12 |
+
result_dict[line_without_trailing_comma] = True
|
13 |
+
return result_dict
|
14 |
+
|
15 |
+
ignore1 = load_ignore('ignoreTag.txt')
|
16 |
+
ignore2 = load_ignore('ignoreTag2.txt')
|
17 |
+
|
18 |
+
def is_ignore(tag, ignore_type):
|
19 |
+
if ignore_type == 1:
|
20 |
+
return tag in ignore1 or tag in ignore2
|
21 |
+
elif ignore_type == 2:
|
22 |
+
return tag in ignore1
|