Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,43 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
#
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
img = transform(image).unsqueeze(0)
|
23 |
-
model.eval()
|
24 |
-
with torch.no_grad():
|
25 |
-
output = model(img)
|
26 |
-
prediction = torch.argmax(output, dim=1).item()
|
27 |
-
|
28 |
-
# Define class names
|
29 |
-
class_names = ["Not Katy Perry", "Katy Perry"]
|
30 |
-
|
31 |
-
return class_names[prediction]
|
32 |
-
|
33 |
-
# Set up the Gradio interface
|
34 |
-
iface = gr.Interface(
|
35 |
-
fn=predict,
|
36 |
-
inputs=gr.inputs.Image(type="pil"),
|
37 |
-
outputs="text",
|
38 |
-
title="Katy Perry Recognition",
|
39 |
-
description="Upload an image to find out if it's Katy Perry or not.",
|
40 |
-
)
|
41 |
-
|
42 |
-
if __name__ == "__main__":
|
43 |
-
iface.launch()
|
|
|
1 |
+
|
2 |
+
__all__ = ['is_katy', 'learn', 'classify_image', 'categories', 'image', 'label', 'examples', 'intf']
|
3 |
+
|
4 |
+
# Cell
|
5 |
+
from fastai.vision.all import *
|
6 |
import gradio as gr
|
7 |
+
|
8 |
+
def is_katy(x): return x[0].isupper()
|
9 |
+
|
10 |
+
# Cell
|
11 |
+
learn = load_learner('model.pkl')
|
12 |
+
|
13 |
+
# Cell
|
14 |
+
categories = ('Katy', 'Zooey')
|
15 |
+
|
16 |
+
def classify_image(img):
|
17 |
+
pred,idx,probs = learn.predict(img)
|
18 |
+
return dict(zip(categories, map(float,probs)))
|
19 |
+
|
20 |
+
# Cell
|
21 |
+
image = gr.inputs.Image(shape=(192, 192))
|
22 |
+
label = gr.outputs.Label()
|
23 |
+
examples = ['katy.jpg', 'katy2.jpg','zooey1.jpg','zooey2.jpg','zooey3.jpg','dunno.jpg']
|
24 |
+
|
25 |
+
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
|
26 |
+
intf.launch(inline=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|