minina / app.py
ruidanwang's picture
Update app.py
18c00a7 verified
raw
history blame
713 Bytes
# prompt: gradio image 分类
import fastai
from fastai.vision import *
from fastai.vision.learner import load_learner
from PIL import Image
import gradio as gr
# Load the model
model = load_learner("model.pkl")
# Define an image classification function
def classify_image(image):
# Preprocess the image
image = Image.create(image).resize((192, 192))
# Make a prediction
prediction = model.predict(image)[0]
# Return the prediction
return {prediction: 1.0}
# Create the Gradio interface
image_input = gr.Image()
label_output = gr.Label(num_top_classes=3)
interface = gr.Interface(fn=classify_image, inputs=image_input, outputs=label_output)
# Launch the interface
interface.launch()