File size: 1,173 Bytes
d16e3d9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#|export
from fastai.vision.all import *
import os
import gradio as gr
def is_flower(x): return x[0].isupper()

#export
learn = load_learner('mexicanPlants (1).pkl')


#|export
categories = ('Jacaranda', 'Bougainvillea', 'Clavalina tree', 'Birds of paradise plant oaxaca', 'Flame vine', 'Plumeria rubra', 'Ceiba speciosa', 'Poinsettia tree', 'Calistemo', 'Flamboyan', 'Mexican creeper','primavera rosa')

def classify_image(img):
    pred,idx,probs = learn.predict(img)
    return dict(zip(categories,map(float,probs)))


# Get the current directory
current_dir = os.getcwd()

# Get a list of all files in the directory
all_files = os.listdir(current_dir)

# Create a list of categories

# Create an empty list to store the photos
photos = []

# Loop through all the files
for file in all_files:
    # Check if the file is a photo
    if file.endswith(('.jpg', '.jpeg', '.png', '.bmp', '.gif')):
        # If it is, add it to the list of photos
        photos.append(file)

image = gr.inputs.Image(shape=(192,192))
label = gr.outputs.Label()
examples = photos

intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
intf.launch(inline=False)