Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Import the necessary libraries
|
2 |
+
from fastai.vision.all import *
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
# Load the trained model
|
6 |
+
learn = load_learner('export.pkl')
|
7 |
+
|
8 |
+
# Get the labels from the model's dataloader
|
9 |
+
labels = learn.dls.vocab
|
10 |
+
|
11 |
+
# Function to classify an image using the model
|
12 |
+
def classify_image(img):
|
13 |
+
pred,pred_idx,probs = learn.predict(img)
|
14 |
+
return dict(zip(labels, probs))
|
15 |
+
|
16 |
+
|
17 |
+
# Create the Gradio interface
|
18 |
+
image_input = gr.components.Image()
|
19 |
+
label_output = gr.components.Label()
|
20 |
+
|
21 |
+
examples = [f"assets/{fn}" for fn in ["bergen.jpg", "oslo.jpg", "newyork.jpg"]]
|
22 |
+
|
23 |
+
iface = gr.Interface(
|
24 |
+
fn=classify_image,
|
25 |
+
inputs=image_input,
|
26 |
+
outputs=label_output,
|
27 |
+
examples=examples
|
28 |
+
)
|
29 |
+
|
30 |
+
iface.launch(inline=False)
|