MonkeyJuice commited on
Commit
de8aa71
·
verified ·
1 Parent(s): d050176
Files changed (1) hide show
  1. app.py +15 -2
app.py CHANGED
@@ -19,6 +19,12 @@ def predict(image: PIL.Image.Image):
19
  result_text = '<div id="m5dd_result">' + ', '.join(result_filter.keys()) + '</div>'
20
  return result_html, result_text
21
 
 
 
 
 
 
 
22
  def predict_batch(zip_file, progress=gr.Progress()):
23
  result = ''
24
  with zipfile.ZipFile(zip_file) as zf:
@@ -53,6 +59,7 @@ with gr.Blocks(head_paths="head.html") as demo:
53
  batch_file = gr.File(label="Upload a ZIP file containing images",
54
  file_types=['.zip'])
55
  run_button2 = gr.Button('Run')
 
56
  with gr.Column(scale=2):
57
  result_text2 = gr.Textbox(lines=20,
58
  max_lines=20,
@@ -63,13 +70,19 @@ with gr.Blocks(head_paths="head.html") as demo:
63
  fn=predict,
64
  inputs=[image],
65
  outputs=[result_html, result_text],
66
- api_name='predict',
67
  )
68
  run_button2.click(
69
  fn=predict_batch,
70
  inputs=[batch_file],
71
  outputs=[result_text2],
72
- api_name='predict_batch',
 
 
 
 
 
 
73
  )
74
 
75
  if __name__ == "__main__":
 
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)
24
+ result_filter = {key: value for key, value in result_threshold.items() if not is_ignore(key, 2)}
25
+ tag = ', '.join(result_filter.keys())
26
+ return str(tag)
27
+
28
  def predict_batch(zip_file, progress=gr.Progress()):
29
  result = ''
30
  with zipfile.ZipFile(zip_file) as zf:
 
59
  batch_file = gr.File(label="Upload a ZIP file containing images",
60
  file_types=['.zip'])
61
  run_button2 = gr.Button('Run')
62
+ run_button_api = gr.Button(value: 'Run', visible: False)
63
  with gr.Column(scale=2):
64
  result_text2 = gr.Textbox(lines=20,
65
  max_lines=20,
 
70
  fn=predict,
71
  inputs=[image],
72
  outputs=[result_html, result_text],
73
+ api_name=False,
74
  )
75
  run_button2.click(
76
  fn=predict_batch,
77
  inputs=[batch_file],
78
  outputs=[result_text2],
79
+ api_name=False,
80
+ )
81
+ run_button_api.click(
82
+ fn=predict_api,
83
+ inputs=[image],
84
+ outputs=[result_text2],
85
+ api_name='predict',
86
  )
87
 
88
  if __name__ == "__main__":