Spaces:
Sleeping
Sleeping
dcavadia commited on
Commit ·
3a703d8
1
Parent(s): d200625
update app
Browse files
app.py
CHANGED
|
@@ -1,33 +1,52 @@
|
|
| 1 |
import json
|
| 2 |
-
from keras.models import Model, load_model
|
| 3 |
-
import gradio as gr
|
| 4 |
import cv2
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
|
| 9 |
# Opening JSON file
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
# returns JSON object as
|
| 13 |
-
# a dictionary
|
| 14 |
-
data = json.load(f)
|
| 15 |
|
| 16 |
keys = list(data)
|
| 17 |
|
| 18 |
-
|
| 19 |
def Predict(image):
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import json
|
|
|
|
|
|
|
| 2 |
import cv2
|
| 3 |
+
import numpy as np
|
| 4 |
+
import gradio as gr
|
| 5 |
+
import onnxruntime
|
| 6 |
|
| 7 |
+
# Load the ONNX model
|
| 8 |
+
ort_session = onnxruntime.InferenceSession("modelonnx.onnx")
|
| 9 |
|
| 10 |
# Opening JSON file
|
| 11 |
+
with open('dat.json') as f:
|
| 12 |
+
data = json.load(f)
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
keys = list(data)
|
| 15 |
|
|
|
|
| 16 |
def Predict(image):
|
| 17 |
+
# Preprocess the image
|
| 18 |
+
img = cv2.resize(image, (100, 100)) / 255.0
|
| 19 |
+
|
| 20 |
+
# Run inference with the ONNX model
|
| 21 |
+
input_name = ort_session.get_inputs()[0].name
|
| 22 |
+
output_name = ort_session.get_outputs()[0].name
|
| 23 |
+
result = ort_session.run([output_name], {input_name: img.reshape(1, 3, 100, 100).astype(np.float32)})[0]
|
| 24 |
+
|
| 25 |
+
# Get the index of the predicted class
|
| 26 |
+
prediction_idx = np.argmax(result)
|
| 27 |
+
|
| 28 |
+
# Debugging
|
| 29 |
+
print("Prediction Index:", prediction_idx)
|
| 30 |
+
print("Keys:", keys)
|
| 31 |
+
|
| 32 |
+
# Retrieve information from JSON based on the predicted class
|
| 33 |
+
disease_name = keys[prediction_idx]
|
| 34 |
+
description = data[disease_name]['description']
|
| 35 |
+
symptoms = data[disease_name]['symptoms']
|
| 36 |
+
causes = data[disease_name]['causes']
|
| 37 |
+
treatment = data[disease_name]['treatment-1']
|
| 38 |
+
|
| 39 |
+
return disease_name, description, symptoms, causes, treatment
|
| 40 |
+
|
| 41 |
+
# Define Gradio interface
|
| 42 |
+
demo = gr.Interface(fn=Predict,
|
| 43 |
+
inputs="image",
|
| 44 |
+
outputs=[gr.Textbox(label='Name Of Disease', type="text"),
|
| 45 |
+
gr.Textbox(label='Description', type="text"),
|
| 46 |
+
gr.Textbox(label='Symptoms', type="text"),
|
| 47 |
+
gr.Textbox(label='Causes', type="text"),
|
| 48 |
+
gr.Textbox(label='Treatment', type="text")],
|
| 49 |
+
title="Skin Disease Classification",
|
| 50 |
+
description='This Space predict these disease:\n \n1) Acne and Rosacea Photos. \n2) Actinic Keratosis Basal Cell Carcinoma and other Malignant Lesions.\n3) Eczema Photos. \n4) Melanoma Skin Cancer Nevi and Moles.\n5) Psoriasis pictures Lichen Planus and related diseases.\n6) Tinea Ringworm Candidiasis and other Fungal Infections.\n7) Urticaria Hives.\n8) Nail Fungus and other Nail Disease.\n')
|
| 51 |
+
|
| 52 |
+
demo.launch(debug=True)
|
dat.json
CHANGED
|
@@ -1,59 +1,65 @@
|
|
| 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 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
{
|
| 2 |
+
"actinic keratosis": {
|
| 3 |
+
"description": "Actinic keratosis (AK) is a pre-cancerous area of thick, scaly, or crusty skin. These growths are more common in fair-skinned people and those who are frequently in the sun. They are believed to form when skin gets damaged by ultraviolet (UV) radiation from the sun or indoor tanning beds, usually over the course of decades.",
|
| 4 |
+
"symptoms": "Actinic keratoses (AKs) most commonly present as a white, scaly plaque of variable thickness with surrounding redness",
|
| 5 |
+
"causes": "The most important cause of AK formation is solar radiation, through a variety of mechanisms.",
|
| 6 |
+
"treatment-1": "https://www.skincancer.org/skin-cancer-information/actinic-keratosis/actinic-keratosis-treatment-options",
|
| 7 |
+
"treatment-2": "https://www.skincancer.org/skin-cancer-information/basal-cell-carcinoma/bcc-treatment-options"
|
| 8 |
+
},
|
| 9 |
+
"basal cell carcinoma": {
|
| 10 |
+
"description": "Basal cell carcinoma (BCC) is the most common type of skin cancer. Basal cell carcinoma occurs when one of the skin's basal cells develops a mutation in its DNA. Basal cells are found at the bottom of the epidermis — the outermost layer of skin.",
|
| 11 |
+
"symptoms": "Basal cell carcinomas often look like open sores, red patches, pink growths, shiny bumps, or scars. In some cases, a crusty area bleeds or oozes, but usually, there is little or no sensation.",
|
| 12 |
+
"causes": "The exact cause of basal cell carcinoma is unknown, but several risk factors may increase your chances of developing the disease. Ultraviolet (UV) radiation from the sun is the main cause of basal cell carcinoma.",
|
| 13 |
+
"treatment-1": "https://www.skincancer.org/skin-cancer-information/basal-cell-carcinoma/bcc-treatment-options",
|
| 14 |
+
"treatment-2": "https://www.cancer.gov/types/skin/patient/skin-treatment-pdq"
|
| 15 |
+
},
|
| 16 |
+
"dermatofibroma": {
|
| 17 |
+
"description": "A dermatofibroma is a common benign skin lesion that occurs most often on the extremities of adults. These lesions are considered tumors of the skin and soft tissue and are composed of fibroblastic cells (cells that produce the protein collagen).",
|
| 18 |
+
"symptoms": "Dermatofibromas are typically small, firm, red-brown bumps that are found most frequently on the legs, but can appear on other parts of the body as well.",
|
| 19 |
+
"causes": "The exact cause of dermatofibromas is not known, but they may develop after an insect bite or minor injury to the skin.",
|
| 20 |
+
"treatment-1": "https://www.aad.org/public/diseases/bumps-and-growths/dermatofibroma",
|
| 21 |
+
"treatment-2": "https://emedicine.medscape.com/article/1056744-overview"
|
| 22 |
+
},
|
| 23 |
+
"melanoma": {
|
| 24 |
+
"description": "Melanoma is a type of skin cancer that develops from the pigment-producing cells known as melanocytes. Melanomas typically occur in the skin but may rarely occur in the mouth, intestines, or eye.",
|
| 25 |
+
"symptoms": "Early signs of melanoma are changes to the shape or color of existing moles or the appearance of a new lump anywhere on the skin. At later stages, the mole may itch, ulcerate, or bleed.",
|
| 26 |
+
"causes": "Melanomas are usually caused by DNA damage resulting from exposure to ultraviolet (UV) light from the sun. Genetics also play a role.",
|
| 27 |
+
"treatment-1": "https://www.cancer.org/cancer/melanoma-skin-cancer/treating/by-stage.html",
|
| 28 |
+
"treatment-2": "https://www.melanoma.org/understand-melanoma/melanoma-treatment"
|
| 29 |
+
},
|
| 30 |
+
"nevus": {
|
| 31 |
+
"description": "A nevus is a common, benign growth or birthmark that develops on the skin due to a proliferation of melanocytes, the cells that produce skin pigment.",
|
| 32 |
+
"symptoms": "Nevi can vary greatly in appearance, ranging from flat, pigmented spots to raised, hairy moles. Most nevi are harmless and require no treatment, but some may need to be monitored or removed if they show signs of change or become cancerous.",
|
| 33 |
+
"causes": "The exact cause of nevi is not known, but they are believed to develop as a result of genetic predisposition and exposure to ultraviolet (UV) radiation from the sun.",
|
| 34 |
+
"treatment-1": "https://www.aad.org/public/diseases/bumps-and-growths/nevi",
|
| 35 |
+
"treatment-2": "https://www.skincancer.org/skin-cancer-information/melanoma/moles-and-melanoma"
|
| 36 |
+
},
|
| 37 |
+
"pigmented benign keratosis": {
|
| 38 |
+
"description": "Pigmented benign keratoses are common benign skin lesions that often develop as people age. These lesions typically appear as raised, scaly patches on sun-exposed areas of the skin, such as the face, neck, arms, and hands.",
|
| 39 |
+
"symptoms": "Pigmented benign keratoses usually present as small, brown or black spots with a rough texture. They may be mistaken for melanoma or other types of skin cancer, so it's important to have them evaluated by a dermatologist.",
|
| 40 |
+
"causes": "The exact cause of pigmented benign keratoses is not known, but they are thought to develop as a result of cumulative sun exposure and genetic predisposition.",
|
| 41 |
+
"treatment-1": "https://www.dermnetnz.org/topics/solar-keratosis",
|
| 42 |
+
"treatment-2": "https://www.skincancer.org/skin-cancer-information/solar-keratosis/solar-keratosis-treatment-options"
|
| 43 |
+
},
|
| 44 |
+
"seborrheic keratosis": {
|
| 45 |
+
"description": "Seborrheic keratosis is a common, non-cancerous skin growth that typically appears as a waxy, brown, or black growth on the face, chest, shoulders, or back. These growths are usually painless and do not require treatment unless they become irritated or cosmetically bothersome.",
|
| 46 |
+
"symptoms": "Seborrheic keratoses are often mistaken for moles or warts but have a distinct appearance characterized by a waxy, stuck-on appearance.",
|
| 47 |
+
"causes": "The exact cause of seborrheic keratoses is not known, but they are thought to develop as a result of genetic predisposition and cumulative sun exposure.",
|
| 48 |
+
"treatment-1": "https://www.aad.org/public/diseases/bumps-and-growths/seborrheic-keratoses",
|
| 49 |
+
"treatment-2": "https://www.healthline.com/health/seborrheic-keratosis-removal"
|
| 50 |
+
},
|
| 51 |
+
"squamous cell carcinoma": {
|
| 52 |
+
"description": "Squamous cell carcinoma (SCC) is a common type of skin cancer that develops in the squamous cells that make up the outer layer of the skin. SCC often appears as a red, scaly patch or a raised, wart-like growth that may crust or bleed.",
|
| 53 |
+
"symptoms": "Early signs of SCC include persistent sores, rough scaly patches, or elevated growths that may crust or bleed. If left untreated, SCC can grow deeper into the skin and spread to other parts of the body, leading to serious complications.",
|
| 54 |
+
"causes": "The primary cause of SCC is cumulative exposure to ultraviolet (UV) radiation from the sun. Other risk factors include fair skin, a history of sunburns, a weakened immune system, and exposure to certain chemicals or radiation.",
|
| 55 |
+
"treatment-1": "https://www.skincancer.org/skin-cancer-information/squamous-cell-carcinoma/",
|
| 56 |
+
"treatment-2": "https://www.cancer.org/cancer/squamous-cell-skin-cancer/treating/by-stage.html"
|
| 57 |
+
},
|
| 58 |
+
"vascular lesion": {
|
| 59 |
+
"description": "Vascular lesions are abnormal clusters of blood vessels that can appear on the skin's surface. These lesions can be categorized as either vascular tumors or vascular malformations, depending on their structure and behavior.",
|
| 60 |
+
"symptoms": "The symptoms of vascular lesions can vary depending on their type and location. Common symptoms include red or purple discoloration, swelling, pain, and changes in skin texture.",
|
| 61 |
+
"causes": "The exact cause of vascular lesions is not always known, but they are believed to result from abnormal development or damage to blood vessels during fetal development, injury, or other underlying medical conditions.",
|
| 62 |
+
"treatment-1": "https://www.mayoclinic.org/diseases-conditions/hemangioma/symptoms-causes/syc-20372935",
|
| 63 |
+
"treatment-2": "https://www.webmd.com/skin-problems-and-treatments/guide/vascular-lesions#1"
|
| 64 |
+
}
|
| 65 |
+
}
|