File size: 1,706 Bytes
8cb8f64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import os
import textwrap
import time

import gradio as gr
from PIL import Image

from check import DEFAULT_MODEL, predict, MODELS


def _predict_fn(image: Image.Image, model_name: str = DEFAULT_MODEL, max_batch_size: int = 8):
    start_time = time.time()
    result = predict(image, model_name, max_batch_size)
    duration = time.time() - start_time
    info = f'Time cost: **{duration:.3f}s**'
    return result, info


if __name__ == '__main__':
    with gr.Blocks() as demo:
        with gr.Row():
            gr_info = gr.Markdown(textwrap.dedent("""
                 Quickly check if the image is **glazed or misted** (we call it shat💩).

                 And then you can just remove these shit with
                 [mf666/mist-fucker](https://huggingface.co/spaces/mf666/mist-fucker),
                 without fucking the normal images (no detail losses).
            """).strip())

        with gr.Row():
            with gr.Column():
                gr_input = gr.Image(label='Image To Check', image_mode='RGB', type='pil')
                gr_models = gr.Dropdown(choices=MODELS, value=DEFAULT_MODEL, label='Models')
                gr_max_batch_size = gr.Slider(minimum=1, maximum=16, value=8, step=1, label='Max Batch Size')
                gr_submit = gr.Button(value='Check The Shit', variant='primary')

            with gr.Column():
                gr_label = gr.Label(label='Check Result')
                gr_time_cost = gr.Markdown(label='Information')

            gr_submit.click(
                _predict_fn,
                inputs=[gr_input, gr_models, gr_max_batch_size],
                outputs=[gr_label, gr_time_cost],
            )

    demo.queue(os.cpu_count()).launch()