File size: 989 Bytes
1592902 ef0a3b5 dad27ef ef0a3b5 7a81476 1592902 bca784b 6852350 f6077a1 441f9dd 6852350 13ae856 1592902 13ae856 1592902 13ae856 1592902 6852350 13ae856 6852350 13ae856 1592902 6852350 |
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 |
import os
import sys
import subprocess
# Install necessary packages if not already installed
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 *
# Replace 'your_model_path' with the actual path to your model file
learn = load_learner('sphynx.pkl')
# Assuming you have two categories: 'cat' and 'sphinx cat'
categories = ('cat', 'sphinx cat')
def classify_image(im):
pred, idx, probs = learn.predict(im)
return dict(zip(categories, map(float, probs)))
# Define the input component
image = gr.Image()
# Define the output component
label_output = gr.Label()
# Create the Gradio interface
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label_output, examples=["Sphynx.jpg", "cat.jpg"])
intf.launch(share=False)
|