| import os |
| import sys |
| import subprocess |
|
|
| |
| required_packages = ["fastai", "gradio"] |
| for package in required_packages: |
| try: |
| __import__(package) |
| except ImportError: |
| subprocess.run([sys.executable, "-m", "pip", "install", package]) |
|
|
| import gradio as gr |
| from fastai.learner import load_learner |
| from fastai.vision.all import * |
|
|
| |
|
|
| learn = load_learner('sphynx.pkl') |
|
|
| |
| categories = ('cat', 'sphinx cat') |
|
|
| def classify_image(im): |
| pred, idx, probs = learn.predict(im) |
| return dict(zip(categories, map(float, probs))) |
|
|
| |
| image = gr.Image() |
|
|
| |
| label_output = gr.Label() |
|
|
| |
| intf = gr.Interface(fn=classify_image, inputs=image, outputs=label_output, examples=["Sphynx.jpg", "cat.jpg"]) |
| intf.launch(share=False) |
|
|
|
|