Spaces:
Runtime error
Runtime error
confidence scores added...
#4
by
doesntMatter11
- opened
app.py
CHANGED
@@ -1,33 +1,60 @@
|
|
1 |
import json
|
2 |
-
from keras.models import
|
|
|
3 |
import gradio as gr
|
4 |
import cv2
|
|
|
5 |
|
|
|
|
|
6 |
|
7 |
-
model
|
|
|
8 |
|
9 |
-
#
|
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 |
+
from keras.models import load_model
|
3 |
+
from keras.optimizers import Adam
|
4 |
import gradio as gr
|
5 |
import cv2
|
6 |
+
import numpy as np
|
7 |
|
8 |
+
# Load the model without compiling
|
9 |
+
model = load_model('final_vgg1920epochs.h5', compile=False)
|
10 |
|
11 |
+
# Compile the model with the desired optimizer and learning rate
|
12 |
+
model.compile(optimizer=Adam(learning_rate=0.001), loss='categorical_crossentropy', metrics=['accuracy'])
|
13 |
|
14 |
+
# Open JSON file
|
15 |
+
with open('dat.json') as f:
|
16 |
+
data = json.load(f)
|
|
|
|
|
|
|
17 |
|
18 |
keys = list(data)
|
19 |
|
|
|
20 |
def Predict(image):
|
21 |
+
# Preprocess the image
|
22 |
+
img = cv2.resize(image, (32, 32)) / 255.0
|
23 |
+
prediction = model.predict(img.reshape(1, 32, 32, 3))
|
24 |
+
|
25 |
+
# Get the predicted class and confidence score
|
26 |
+
predicted_class_index = prediction.argmax()
|
27 |
+
predicted_class = keys[predicted_class_index]
|
28 |
+
confidence_score = prediction[0][predicted_class_index] * 100 # Convert to percentage
|
29 |
+
|
30 |
+
# Retrieve details from the JSON data
|
31 |
+
description = data[predicted_class]['description']
|
32 |
+
symptoms = data[predicted_class]['symptoms']
|
33 |
+
causes = data[predicted_class]['causes']
|
34 |
+
treatment = data[predicted_class]['treatement-1']
|
35 |
+
|
36 |
+
return (
|
37 |
+
predicted_class,
|
38 |
+
description,
|
39 |
+
symptoms,
|
40 |
+
causes,
|
41 |
+
treatment,
|
42 |
+
f"{confidence_score:.2f}%" # Format the confidence score
|
43 |
+
)
|
44 |
+
|
45 |
+
demo = gr.Interface(
|
46 |
+
fn=Predict,
|
47 |
+
inputs=gr.Image(type="numpy"), # Updated to use the new interface
|
48 |
+
outputs=[
|
49 |
+
gr.Textbox(label='Name Of Disease'),
|
50 |
+
gr.Textbox(label='Description'),
|
51 |
+
gr.Textbox(label='Symptoms'),
|
52 |
+
gr.Textbox(label='Causes'),
|
53 |
+
gr.Textbox(label='Treatment'),
|
54 |
+
gr.Textbox(label='Confidence Score')
|
55 |
+
],
|
56 |
+
title="Skin Disease Classification",
|
57 |
+
description='This Space predicts these diseases:\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 Diseases.\n'
|
58 |
+
)
|
59 |
+
|
60 |
+
demo.launch(debug=True)
|