Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
from fastai.vision.all import *
|
|
|
|
|
3 |
|
4 |
# Re-define the GrayscaleTransform class (same as during training)
|
5 |
class GrayscaleTransform(Transform):
|
@@ -14,8 +16,28 @@ def classify_waterfowl(img):
|
|
14 |
pred, pred_idx, probs = learn.predict(img)
|
15 |
return {learn.dls.vocab[i]: float(probs[i]) for i in range(len(probs))}
|
16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
# Create a Gradio interface
|
18 |
-
interface = gr.Interface(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
# Launch the Gradio app
|
21 |
-
interface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from fastai.vision.all import *
|
3 |
+
import requests
|
4 |
+
from PIL import Image
|
5 |
|
6 |
# Re-define the GrayscaleTransform class (same as during training)
|
7 |
class GrayscaleTransform(Transform):
|
|
|
16 |
pred, pred_idx, probs = learn.predict(img)
|
17 |
return {learn.dls.vocab[i]: float(probs[i]) for i in range(len(probs))}
|
18 |
|
19 |
+
# Provide some example images
|
20 |
+
examples = [
|
21 |
+
['https://upload.wikimedia.org/wikipedia/commons/7/74/White_domesticated_duck,_stretching.jpg'],
|
22 |
+
['https://upload.wikimedia.org/wikipedia/commons/3/39/Domestic_Goose.jpg'],
|
23 |
+
['https://upload.wikimedia.org/wikipedia/commons/a/a2/CygneVaires.jpg']
|
24 |
+
]
|
25 |
+
|
26 |
+
# Description and instructions for users
|
27 |
+
description = """
|
28 |
+
This is an AI model trained to differentiate between ducks, geese, and swans. You can upload your own image or use one of the example images below.
|
29 |
+
Try uploading an image of a duck, goose, or swan and see if the model can correctly classify it.
|
30 |
+
"""
|
31 |
+
|
32 |
# Create a Gradio interface
|
33 |
+
interface = gr.Interface(
|
34 |
+
fn=classify_waterfowl,
|
35 |
+
inputs=gr.Image(type="pil"),
|
36 |
+
outputs=gr.Label(),
|
37 |
+
examples=examples, # Add example images
|
38 |
+
description=description, # Add instructions for users
|
39 |
+
title="Duck, Goose, or Swan Classifier"
|
40 |
+
)
|
41 |
|
42 |
# Launch the Gradio app
|
43 |
+
interface.launch()
|