| import fastai |
| import gradio as gr |
| from fastai.vision.all import * |
|
|
|
|
|
|
| def search_images(term, max_images=50): |
| print(f"Searching for '{term}'") |
| return L(search_images_ddg(term, max_results=max_images)).itemgot('image') |
| def classify_image(img): |
| pred,idx,probs = learn.predict(img) |
| return dict(zip(categories,map(float,probs))) |
|
|
| learn = load_learner('model.pkl') |
| categories = ('black','grizzly','polar','teddy') |
| image = gr.inputs.Image(shape = (224,224)) |
| label = gr.outputs.Label() |
| examples = ['grizzly.jpg','black.jpg','teddy.jpg','polar.jpg'] |
|
|
| intf = gr.Interface(fn=classify_image,inputs = image,outputs = label,examples = examples) |
| intf.launch(inline = False) |