|
import gradio as gr |
|
from glob import glob |
|
from PIL import Image |
|
from explain import get_results, reproduce |
|
|
|
|
|
def classify_and_explain(image, object_detection=False): |
|
reproduce() |
|
|
|
list_of_images = get_results(img_for_testing=image, od=object_detection) |
|
return list_of_images |
|
|
|
|
|
def get_examples(): |
|
|
|
od_off_examples = [ |
|
"samples/DSC_0315.jpg", |
|
"samples/20210401_123624.jpg", |
|
"samples/IMG_1299.jpg", |
|
"samples/20210420_112400.jpg", |
|
"samples/IMG_1300.jpg", |
|
"samples/20210420_112406.jpg", |
|
] |
|
|
|
return [ |
|
[Image.open(i), True] for i in glob("samples/*") if i not in od_off_examples |
|
] + [[Image.open(i), False] for i in glob("samples/*") if i in od_off_examples] |
|
|
|
|
|
demo = gr.Interface( |
|
fn=classify_and_explain, |
|
inputs=[ |
|
"image", |
|
gr.Checkbox( |
|
label="Extract Leaves", info="What to extract leafs before classification" |
|
), |
|
], |
|
outputs="gallery", |
|
examples=get_examples(), |
|
) |
|
demo.launch() |
|
|