Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,36 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
|
|
|
|
5 |
|
6 |
-
iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
7 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import numpy as np # linear algebra
|
3 |
+
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
|
4 |
+
import os # operating system
|
5 |
+
from fastai.vision.all import * # fastai stuff
|
6 |
+
import gradio as gr
|
7 |
+
|
8 |
+
def is_cat(x): return x[0].isupper()
|
9 |
+
|
10 |
+
dls = ImageDataLoaders.from_name_func('.',
|
11 |
+
get_image_files(path), valid_pct=0.2, seed=42,
|
12 |
+
label_func=is_cat,
|
13 |
+
item_tfms=Resize(192))
|
14 |
+
|
15 |
+
learn = vision_learner(dls, resnet18, metrics=error_rate)
|
16 |
+
# fine_tune() method automatically uses best practices for fine tuning
|
17 |
+
# a pre-trained model
|
18 |
+
learn.fine_tune(3)
|
19 |
+
|
20 |
+
|
21 |
+
learn.export('model.pkl')
|
22 |
+
|
23 |
+
learn_inf = load_learner(path/'model.pkl')
|
24 |
+
|
25 |
+
|
26 |
+
categories =('Dog','Cat')
|
27 |
+
def classify_image(img):
|
28 |
+
pred, idx, probs = learn_inf.predict(img)
|
29 |
+
return dict(zip(categories, map(float, probs)))
|
30 |
|
31 |
+
image = gr.inputs.Image(shape=(192,192))
|
32 |
+
label = gr.outputs.Label()
|
33 |
+
examples = ['dog.jpeg','cat.jpeg','catdog.jpeg']
|
34 |
+
intt = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
|
35 |
|
|
|
36 |
iface.launch()
|