Spinn / app.py
Sabse's picture
Update app.py
f6077a1
raw
history blame contribute delete
989 Bytes
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)