MonkeyJuice commited on
Commit
228bfd8
1 Parent(s): c410097

Update app.py

Browse files
Files changed (3) hide show
  1. app.py +13 -9
  2. script.js +17 -21
  3. style.css +4 -0
app.py CHANGED
@@ -19,7 +19,7 @@ def predict(image: PIL.Image.Image, score_threshold: float):
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()):
@@ -34,7 +34,7 @@ def predict_batch(zip_file, score_threshold: float, progress=gr.Progress()):
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
 
40
  with gr.Blocks(css="style.css", js="script.js") as demo:
@@ -43,23 +43,26 @@ with gr.Blocks(css="style.css", js="script.js") as demo:
43
  with gr.Column(scale=1):
44
  image = gr.Image(label='Upload a image',
45
  type='pil',
46
- sources=["upload", "clipboard"],
47
- height='20em')
48
  score_threshold = gr.Slider(label='Score threshold',
49
  minimum=0,
50
  maximum=1,
51
  step=0.05,
52
  value=0.5)
53
  run_button = gr.Button('Run')
54
- result_text = gr.HTML(value="<div></div>")
55
  with gr.Column(scale=2):
56
- result_html = gr.HTML(value="<div></div>")
 
 
 
 
 
57
  with gr.Tab(label='Batch'):
58
  with gr.Row():
59
  with gr.Column(scale=1):
60
  batch_file = gr.File(label="Upload a ZIP file containing images",
61
- file_types=['.zip'],
62
- height='20em')
63
  score_threshold2 = gr.Slider(label='Score threshold',
64
  minimum=0,
65
  maximum=1,
@@ -67,7 +70,8 @@ with gr.Blocks(css="style.css", js="script.js") as demo:
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
 
 
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 = ', '.join(result_filter.keys())
23
  return result_html, result_text
24
 
25
  def predict_batch(zip_file, score_threshold: float, progress=gr.Progress()):
 
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\n'
38
  return result
39
 
40
  with gr.Blocks(css="style.css", js="script.js") as demo:
 
43
  with gr.Column(scale=1):
44
  image = gr.Image(label='Upload a image',
45
  type='pil',
46
+ elem_classes='m5dd_image',
47
+ sources=["upload", "clipboard"])
48
  score_threshold = gr.Slider(label='Score threshold',
49
  minimum=0,
50
  maximum=1,
51
  step=0.05,
52
  value=0.5)
53
  run_button = gr.Button('Run')
 
54
  with gr.Column(scale=2):
55
+ result_text = gr.Textbox(lines=3,
56
+ max_lines=3,
57
+ label='Result',
58
+ show_copy_button=True,
59
+ elem_id="m5dd_result")
60
+ result_html = gr.HTML(value="")
61
  with gr.Tab(label='Batch'):
62
  with gr.Row():
63
  with gr.Column(scale=1):
64
  batch_file = gr.File(label="Upload a ZIP file containing images",
65
+ file_types=['.zip'])
 
66
  score_threshold2 = gr.Slider(label='Score threshold',
67
  minimum=0,
68
  maximum=1,
 
70
  value=0.5)
71
  run_button2 = gr.Button('Run')
72
  with gr.Column(scale=2):
73
+ result_text2 = gr.Textbox(lines=20,
74
+ max_lines=20,
75
  label='Result',
76
  show_copy_button=True)
77
 
script.js CHANGED
@@ -1,24 +1,20 @@
 
1
 
2
- document.addEventListener('click', function (event) {
3
- let tagItem = event.target.closest('.m5dd_list')
4
- let resultArea = event.target.closest('#m5dd_result')
5
- if (tagItem) {
6
- if (tagItem.classList.contains('use')) {
7
- tagItem.classList.remove('use')
8
- } else {
9
- tagItem.classList.add('use')
10
- }
11
- document.getElementById('m5dd_result').innerText =
12
- Array.from(document.querySelectorAll('.m5dd_list.use>span:nth-child(1)'))
13
  .map(v => v.innerText)
14
  .join(', ')
15
- } else if (resultArea) {
16
- const selection = window.getSelection()
17
- selection.removeAllRanges()
18
- const range = document.createRange()
19
- range.selectNodeContents(resultArea)
20
- selection.addRange(range)
21
- } else {
22
- return
23
- }
24
- })
 
1
+ async () => {
2
 
3
+ document.addEventListener('click', function (event) {
4
+ let tagItem = event.target.closest('.m5dd_list')
5
+ if (tagItem) {
6
+ if (tagItem.classList.contains('use')) {
7
+ tagItem.classList.remove('use')
8
+ } else {
9
+ tagItem.classList.add('use')
10
+ }
11
+ document.querySelector('#m5dd_result textarea').value = Array
12
+ .from(document.querySelectorAll('.m5dd_list.use>span:nth-child(1)'))
 
13
  .map(v => v.innerText)
14
  .join(', ')
15
+ } else {
16
+ return
17
+ }
18
+ })
19
+
20
+ }
 
 
 
 
style.css CHANGED
@@ -21,3 +21,7 @@
21
  text-decoration: line-through;
22
  color: #ccc;
23
  }
 
 
 
 
 
21
  text-decoration: line-through;
22
  color: #ccc;
23
  }
24
+
25
+ .m5dd_image .upload-container .image-frame {
26
+ height: 20em;
27
+ }