Spaces:
Build error
Build error
Commented out unused imports and removed unnecessary code
Browse files
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
from fastai.vision.all import *
|
| 3 |
import os
|
| 4 |
|
|
@@ -13,22 +13,14 @@ def classify_image(img):
|
|
| 13 |
|
| 14 |
# image = gr.Image(shape=(192, 192))
|
| 15 |
# label = gr.outputs.Label()
|
| 16 |
-
examples = ['cristiano.jpg', 'messi.jpg', './images/cristiano.jpg', './images/messi.jpg']
|
| 17 |
# A function to display photos from the root images folder
|
| 18 |
|
| 19 |
-
# def get_image(path):
|
| 20 |
-
# with open(path, 'rb') as f:
|
| 21 |
-
# return f.read()
|
| 22 |
-
|
| 23 |
-
# def get_image_path(path):
|
| 24 |
-
# return path
|
| 25 |
-
|
| 26 |
-
# print(get_image("images/cristiano.jpg"))
|
| 27 |
|
| 28 |
|
| 29 |
intf = gr.Interface(
|
| 30 |
-
classify_image, gr.Image(type="pil"),
|
| 31 |
-
|
|
|
|
| 32 |
)
|
| 33 |
intf.launch(inline=False)
|
| 34 |
|
|
|
|
| 1 |
+
#import gradio as gr
|
| 2 |
from fastai.vision.all import *
|
| 3 |
import os
|
| 4 |
|
|
|
|
| 13 |
|
| 14 |
# image = gr.Image(shape=(192, 192))
|
| 15 |
# label = gr.outputs.Label()
|
|
|
|
| 16 |
# A function to display photos from the root images folder
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
|
| 20 |
intf = gr.Interface(
|
| 21 |
+
fn=classify_image, inputs=gr.Image(type="pil"),
|
| 22 |
+
outputs=gr.Label(num_top_classes=2),
|
| 23 |
+
examples=['images/cristiano.jpg', 'images/messi.jpg']
|
| 24 |
)
|
| 25 |
intf.launch(inline=False)
|
| 26 |
|
tmp.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# import gradio as gr
|
| 2 |
+
from fastai.vision.all import *
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
categories = ("Cristiano Ronaldo", "Lionel Messi")
|
| 7 |
+
|
| 8 |
+
#model = load_learner('model.pkl')
|
| 9 |
+
|
| 10 |
+
def classify_image(img):
|
| 11 |
+
pred, idx, probs = model.predict(img)
|
| 12 |
+
return dict(zip(categories, map(float, probs)))
|
| 13 |
+
|
| 14 |
+
# image = gr.Image(shape=(192, 192))
|
| 15 |
+
# label = gr.outputs.Label()
|
| 16 |
+
examples = ['cristiano.jpg', 'messi.jpg', './images/cristiano.jpg', './images/messi.jpg']
|
| 17 |
+
# A function to display photos from the root images folder
|
| 18 |
+
|
| 19 |
+
# def get_image(path):
|
| 20 |
+
# with open(path, 'rb') as f:
|
| 21 |
+
# return f.read()
|
| 22 |
+
|
| 23 |
+
# def get_image_path(path):
|
| 24 |
+
# return path
|
| 25 |
+
|
| 26 |
+
# print(get_image("images/cristiano.jpg"))
|
| 27 |
+
import matplotlib.pyplot as plt
|
| 28 |
+
import matplotlib.image as mpimg
|
| 29 |
+
image = mpimg.imread('images/cristiano.jpg')
|
| 30 |
+
plt.imshow(image)
|
| 31 |
+
plt.show()
|
| 32 |
+
|
| 33 |
+
intf = gr.Interface(
|
| 34 |
+
classify_image, gr.Image(type="pil"),
|
| 35 |
+
"image",
|
| 36 |
+
)
|
| 37 |
+
intf.launch(inline=False)
|
| 38 |
+
|