Plana-Archive commited on
Commit
2f24914
·
verified ·
1 Parent(s): dcc6587

Upload danbooru_character_search/app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. danbooru_character_search/app.py +36 -0
danbooru_character_search/app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ import gradio as gr
4
+ from PIL import Image
5
+
6
+ from index import query_character
7
+
8
+
9
+ def _fn(image: Image.Image, count: int = 10, threshold: float = 0.8):
10
+ return query_character(image, count, order_by='same_ratio', threshold=threshold)
11
+
12
+
13
+ if __name__ == '__main__':
14
+ with gr.Blocks() as demo:
15
+ with gr.Row():
16
+ with gr.Column():
17
+ gr_input_image = gr.Image(type='pil', label='Original Image')
18
+ gr_max_count = gr.Slider(minimum=1, maximum=30, step=1, value=10, label='Max Query Count')
19
+ gr_threshold = gr.Slider(minimum=0.0, maximum=0.99, step=0.01, value=0.8, label='Threshold')
20
+ gr_submit = gr.Button(value='Submit', variant='primary')
21
+
22
+ with gr.Column():
23
+ with gr.Tabs():
24
+ with gr.Tab('Gallery'):
25
+ gr_gallery = gr.Gallery(label='Gallery')
26
+
27
+ with gr.Tab('Information'):
28
+ gr_table = gr.DataFrame(label='Information')
29
+
30
+ gr_submit.click(
31
+ _fn,
32
+ inputs=[gr_input_image, gr_max_count, gr_threshold],
33
+ outputs=[gr_gallery, gr_table],
34
+ )
35
+
36
+ demo.queue(os.cpu_count()).launch()