import os import gradio as gr from PIL import Image from index import query_character def _fn(image: Image.Image, count: int = 10, threshold: float = 0.8): return query_character(image, count, order_by='same_ratio', threshold=threshold) if __name__ == '__main__': with gr.Blocks() as demo: with gr.Row(): with gr.Column(): gr_input_image = gr.Image(type='pil', label='Original Image') gr_max_count = gr.Slider(minimum=1, maximum=30, step=1, value=10, label='Max Query Count') gr_threshold = gr.Slider(minimum=0.0, maximum=0.99, step=0.01, value=0.8, label='Threshold') gr_submit = gr.Button(value='Submit', variant='primary') with gr.Column(): with gr.Tabs(): with gr.Tab('Gallery'): gr_gallery = gr.Gallery(label='Gallery') with gr.Tab('Information'): gr_table = gr.DataFrame(label='Information') gr_submit.click( _fn, inputs=[gr_input_image, gr_max_count, gr_threshold], outputs=[gr_gallery, gr_table], ) demo.queue(os.cpu_count()).launch()