Mexican-Flowers / app.py
njc-ai
update app model
d8748f0
raw
history blame contribute delete
No virus
977 Bytes
#|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 = learn.dls.vocab
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 photosgi
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)