Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,18 @@
|
|
| 1 |
from fastai.vision.all import *
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
-
#
|
| 5 |
categories = ['dog', 'cat']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
learn = load_learner('model.pkl')
|
| 7 |
|
| 8 |
-
|
|
|
|
| 9 |
pred, idx, probs = learn.predict(img)
|
| 10 |
return {categories[i]: float(probs[i]) for i in range(len(categories))}
|
| 11 |
|
|
@@ -16,7 +23,7 @@ examples = [['dog.jpg'], ['cat.jpg']]
|
|
| 16 |
|
| 17 |
# Create and launch the interface
|
| 18 |
interface = gr.Interface(
|
| 19 |
-
fn=
|
| 20 |
inputs=image,
|
| 21 |
outputs=label,
|
| 22 |
examples=examples,
|
|
|
|
| 1 |
from fastai.vision.all import *
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
+
# Define categories
|
| 5 |
categories = ['dog', 'cat']
|
| 6 |
+
|
| 7 |
+
# Define the function that was used during training
|
| 8 |
+
def is_cat(x):
|
| 9 |
+
return x[0].isupper()
|
| 10 |
+
|
| 11 |
+
# Load the model
|
| 12 |
learn = load_learner('model.pkl')
|
| 13 |
|
| 14 |
+
# Gradio prediction function
|
| 15 |
+
def predict_image(img):
|
| 16 |
pred, idx, probs = learn.predict(img)
|
| 17 |
return {categories[i]: float(probs[i]) for i in range(len(categories))}
|
| 18 |
|
|
|
|
| 23 |
|
| 24 |
# Create and launch the interface
|
| 25 |
interface = gr.Interface(
|
| 26 |
+
fn=predict_image,
|
| 27 |
inputs=image,
|
| 28 |
outputs=label,
|
| 29 |
examples=examples,
|