Mexican-Flowers / app.py
njc-ai
First model upload and commit
d16e3d9
raw
history blame
No virus
1.17 kB
#|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)