File size: 3,054 Bytes
90d3ef2 85e3812 6486bc3 85e3812 e7376ad 85e3812 c16ecc3 90d3ef2 c16ecc3 90d3ef2 d9a6e4b 089b232 6486bc3 c32ea00 d06c429 c16ecc3 58a1b2f 90d3ef2 |
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 |
__all__ = ['learn', 'classify_image', 'categories', 'image', 'label', 'examples', 'intf']
from fastai.vision.all import *
import gradio as gr
learn = load_learner('export.pkl')
#export.pkl is the name of the neural network file, change accordingly
#below is the dictionary
labels = ['cuts_and_wounds','fracture','rash','splinter']
urls = ['A Cut: Stop the bleeding using a washcloth or bandage and gently apply pressure to the wound. Clean the wound with soap and water. Once it appears clean, pat dry. Wrap the wound with a bandage (smaller wounds dont need this step, just make sure they stay dry and clean ). If the wound has dirt in it, the wound is sensitive, the person starts running a fever, or the wound is because of an animal or human bite, then go to the hospital', 'A Fracture: A fracture is when a bone on your body has a little crack in it. If you feel discomfort in your bone, and it looks a little swollen, you most likely have a fracture. Do not to move the part of your body that is hurt. Do not eat or drink just in case you need to take medicine. Get someone near you to call an ambulance, or get to the hospital.', 'A Rash: If a spot on your skin is red and is itchy, red, painful, or very irritated in an area you should avoid scrubbing the skin. If you can use gentle cleansers, wash the irritated area, avoid applying products that can upset and irritate the skin more. Use warm water to clean the infected area and if it’s still hurting , go to the hospital.','A Splinter: Wash your hands and the wound with soapy water. If you can, soak the area with the wound in warm water. DO NOT SQUEEZE OR PINCH THE SPLINTER OUT. If the splinter is still showing outside of your skin try this method. Get tweezers and clean them with rubbing alcohol and a washcloth. Take note of which way the tweezer is going in. Use the tweezers to grab the part of the splinter sticking out. Pull in the same direction that the splinter went in. If the splinter is tiny or a plant sticker try this method. Get a very sticky tape, like duct tape or packing tape. Gently touch the splintered area with tape and try not to apply too much pressure.When the splinter sticks to the tape, let it sit for 15-30 minutes before gently pulling from skin. Repeat if necessary']
resources = dict(zip(labels, urls))
#End of dictionary
#categories = ('cuts_and_wounds', 'fracture', 'rash', 'splinter')
def classify_image(img):
pred, idx, probs = learn.predict(img)
return dict(zip(urls, map(float, probs)))
image=gr.Image(height = 350, width = 350)
label = gr.Label(num_top_classes=4)
#the num_top_classes=x means one result, could change it
#better_label = gr.Label()
examples = ['Cuts_for_nn.jpeg', 'Fracture_examp.jpeg', 'Rash.jpeg', 'Splinter_examp.jpeg', 'Splinter_download.jpeg', 'Cut_download.jpeg', 'Rash_download.jpeg', 'Fracture_download.jpeg']
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
#(resources.get(str(label))) is how to add the dictionary, add to the output somehow
intf.launch(inline=False) |