CoolFace
Apppublic

GalvanizedHeart/ClimateID

sourceHugging Faceapache-2.0updated 3y agoView on Hugging Face
0likes
app.py29 linesDownload Raw Back to root
1# You need a requirements.txt file for dependencies in Spaces ('pipreqs /path' or 'pipreqs' in CWD will2# automatically generate a requirements.txt file for you).3 4import gradio as gr5from fastai.vision.all import *6 7categories = ("alpine", "desert", "humid continental", "humid subtropical", "ice cap", 8"oceanic plant", "subarctic plant", "semi-arid plant", "mediterranean", "tropical monsoon", 9"tropical rainforest plant", "tropical savanna plant", "tundra plant", "polar")10 11learn = load_learner("model.pkl")12 13# Gradio needs a function14def classify_image(img):15	pred, idx, probs = learn.predict(img)16	return dict(zip(categories, map(float, probs)))17 18# Build the Gradio interface19image = gr.Image(shape=(192,192))20label = gr.Label()21examples = ["polar.jpg", "mediterranean.jpg", "humid_subtropical.jpg"]22 23intf = gr.Interface(fn=classify_image, 24										inputs=image, 25										outputs=label, 26										examples=examples)27 28# This will give us a link to play with the model in app29intf.launch(inline=False)