Spaces:
Sleeping
Sleeping
import gradio as gr | |
from fastai.vision.all import * | |
title = "Interstellar" | |
description = ( | |
"Experimental Astronomical Classifier built for the fast.ai 'Deep Learning' " | |
"course by fine tuning ResNet50 (1 + 3 epochs) with a custom dataset " | |
"of images (150 per label with augmentation)." | |
) | |
inputs = gr.components.Image() | |
outputs = gr.components.Label() | |
examples = "examples" | |
model_class = load_learner("models/model.class.pkl") | |
labels_class = model_class.dls.vocab | |
model_object = load_learner("models/model.object.pkl") | |
labels_object = model_object.dls.vocab | |
def predict_class(img): | |
pred, pred_idx, probs = model_class.predict(img) | |
return dict(zip(labels_class, map(float, probs))) | |
def predict_object(img): | |
pred, pred_idx, probs = model_object.predict(img) | |
return dict(zip(labels_object, map(float, probs))) | |
with gr.Blocks() as demo: | |
with gr.Tab("Class Prediction"): | |
gr.Interface( | |
fn=predict_class, | |
inputs=inputs, | |
outputs=outputs, | |
examples=examples, | |
title=title, | |
description=description, | |
).queue(default_concurrency_limit=5) | |
with gr.Tab("Object Prediction"): | |
gr.Interface( | |
fn=predict_object, | |
inputs=inputs, | |
outputs=outputs, | |
examples=examples, | |
title=title, | |
description=description, | |
).queue(default_concurrency_limit=5) | |
demo.launch() | |