Spaces:
Runtime error
Runtime error
File size: 1,056 Bytes
3c123d7 70fdee2 3c123d7 bc8c176 3c123d7 70fdee2 3c123d7 70fdee2 3c123d7 |
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 |
from pathlib import Path
import gradio as gr
import numpy as np
from fastai.vision.all import *
def label(file_name):
return train_labels[file_name.replace(".jpg", "")]
config = {
"labels": [
"Plantation (0)",
"Grassland (1)",
"Smallholder Agriculture (2)",
],
"size": 256,
}
learn = load_learner("model.pkl")
def classify_image(input):
_, _, prediction = learn.predict(input)
outputs = {label: float(prediction[i]) for i, label in enumerate(config["labels"])}
# Get argmax
argmax_label = config["labels"][np.argmax(prediction)]
return argmax_label, round(outputs[argmax_label], 3) * 100
gr.Interface(
fn=classify_image,
inputs=gr.inputs.Image(shape=(config["size"], config["size"])),
outputs=[
gr.outputs.Textbox(label="Output of the model"),
gr.outputs.Textbox(label="Probability (0 - 100)")
],
examples=[str(x) for x in Path("./").glob("*.png")],
flagging_options=["Correct label", "Incorrect label"],
allow_flagging="manual",
).launch()
|