MonkeyJuice commited on
Commit
935457c
1 Parent(s): bfae66b

Update script.js

Browse files
Files changed (2) hide show
  1. app.py +6 -9
  2. script.js +11 -4
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 = ', '.join(result_filter.keys())
23
  return result_html, result_text
24
 
25
  def predict_batch(zip_file, score_threshold: float, progress=gr.Progress()):
@@ -48,15 +48,11 @@ with gr.Blocks(css="style.css", js="script.js") as demo:
48
  score_threshold = gr.Slider(label='Score threshold',
49
  minimum=0,
50
  maximum=1,
51
- step=0.05,
52
  value=0.3)
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():
@@ -66,14 +62,15 @@ with gr.Blocks(css="style.css", js="script.js") as demo:
66
  score_threshold2 = gr.Slider(label='Score threshold',
67
  minimum=0,
68
  maximum=1,
69
- step=0.05,
70
  value=0.3)
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
 
78
  run_button.click(
79
  fn=predict,
 
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()):
 
48
  score_threshold = gr.Slider(label='Score threshold',
49
  minimum=0,
50
  maximum=1,
51
+ step=0.1,
52
  value=0.3)
53
  run_button = gr.Button('Run')
54
+ result_text = gr.HTML(value="")
55
  with gr.Column(scale=2):
 
 
 
 
 
56
  result_html = gr.HTML(value="")
57
  with gr.Tab(label='Batch'):
58
  with gr.Row():
 
62
  score_threshold2 = gr.Slider(label='Score threshold',
63
  minimum=0,
64
  maximum=1,
65
+ step=0.1,
66
  value=0.3)
67
  run_button2 = gr.Button('Run')
68
  with gr.Column(scale=2):
69
  result_text2 = gr.Textbox(lines=20,
70
  max_lines=20,
71
  label='Result',
72
+ show_copy_button=True,
73
+ autoscroll=False)
74
 
75
  run_button.click(
76
  fn=predict,
script.js CHANGED
@@ -2,16 +2,23 @@ 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
  }
 
2
 
3
  document.addEventListener('click', function (event) {
4
  let tagItem = event.target.closest('.m5dd_list')
5
+ let resultArea = event.target.closest('#m5dd_result')
6
  if (tagItem) {
7
  if (tagItem.classList.contains('use')) {
8
  tagItem.classList.remove('use')
9
  } else {
10
  tagItem.classList.add('use')
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()
19
+ const range = document.createRange()
20
+ range.selectNodeContents(resultArea)
21
+ selection.addRange(range)
22
  } else {
23
  return
24
  }