Upload monochrome_detection/app.py with huggingface_hub
Browse files- monochrome_detection/app.py +32 -0
monochrome_detection/app.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from typing import Mapping
|
| 3 |
+
|
| 4 |
+
import gradio as gr
|
| 5 |
+
from PIL import Image
|
| 6 |
+
|
| 7 |
+
from monochrome import _DEFAULT_MONOCHROME_CKPT, _MONOCHROME_CKPTS, get_monochrome_score
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def monochrome_detect(image: Image.Image, ckpt: str) -> Mapping[str, float]:
|
| 11 |
+
return get_monochrome_score(image, ckpt)
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
if __name__ == '__main__':
|
| 15 |
+
with gr.Blocks() as demo:
|
| 16 |
+
with gr.Row():
|
| 17 |
+
with gr.Column():
|
| 18 |
+
gr_input_image = gr.Image(type='pil', label='Original Image')
|
| 19 |
+
with gr.Row():
|
| 20 |
+
gr_model = gr.Dropdown(_MONOCHROME_CKPTS, value=_DEFAULT_MONOCHROME_CKPT, label='Model')
|
| 21 |
+
|
| 22 |
+
gr_btn_submit = gr.Button(value='Detection', variant='primary')
|
| 23 |
+
|
| 24 |
+
with gr.Column():
|
| 25 |
+
gr_tags = gr.Label(label='Detection')
|
| 26 |
+
|
| 27 |
+
gr_btn_submit.click(
|
| 28 |
+
monochrome_detect,
|
| 29 |
+
inputs=[gr_input_image, gr_model],
|
| 30 |
+
outputs=[gr_tags],
|
| 31 |
+
)
|
| 32 |
+
demo.queue(os.cpu_count()).launch()
|