Spaces:
Runtime error
Runtime error
| # You need a requirements.txt file for dependencies in Spaces ('pipreqs /path' or 'pipreqs' in CWD will | |
| # automatically generate a requirements.txt file for you). | |
| import gradio as gr | |
| from fastai.vision.all import * | |
| categories = ("alpine", "desert", "humid continental", "humid subtropical", "ice cap", | |
| "oceanic plant", "subarctic plant", "semi-arid plant", "mediterranean", "tropical monsoon", | |
| "tropical rainforest plant", "tropical savanna plant", "tundra plant", "polar") | |
| learn = load_learner("model.pkl") | |
| # Gradio needs a function | |
| def classify_image(img): | |
| pred, idx, probs = learn.predict(img) | |
| return dict(zip(categories, map(float, probs))) | |
| # Build the Gradio interface | |
| image = gr.Image(shape=(192,192)) | |
| label = gr.Label() | |
| examples = ["polar.jpg", "mediterranean.jpg", "humid_subtropical.jpg"] | |
| intf = gr.Interface(fn=classify_image, | |
| inputs=image, | |
| outputs=label, | |
| examples=examples) | |
| # This will give us a link to play with the model in app | |
| intf.launch(inline=False) |