File size: 760 Bytes
07a2b58
6755c75
fce2bf4
 
6818f1f
6755c75
07a2b58
6755c75
6818f1f
 
 
fce2bf4
 
 
 
07a2b58
 
 
 
 
 
 
e47236e
 
 
07a2b58
e47236e
6818f1f
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
from fastai.vision.all import *
import gradio as gr
import os
from pathlib import Path
import pathlib

def is_cat(x): return x[0].isupper()

temp = pathlib.PosixPath
pathlib.PosixPath = pathlib.WindowsPath

path = Path(os.path.dirname(os.path.abspath(__file__)))
model_path = path / 'model.pkl'  # Construct the Windows-style path

learn = load_learner(model_path)

categories = ('Dog', 'Cat')

def classify_image(img):
  pred, idx, probs = learn.predict(img)
  return dict(zip(categories, map(float, probs)))

input_component = gr.components.Image(shape=(192,192))
output_component = gr.components.Label()
example = ['dog.jpg']

intf = gr.Interface(fn=classify_image, inputs=input_component, outputs=output_component, examples=example)
intf.launch(share=True)