File size: 711 Bytes
558a694
 
 
0f9a7c2
7927f67
0c17f3d
 
558a694
 
0c17f3d
558a694
 
 
7c6628f
558a694
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# 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.open(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()