doesntMatter11 commited on
Commit
bde57ad
·
verified ·
1 Parent(s): b1797b0

confidence scores added...

Browse files
Files changed (1) hide show
  1. app.py +50 -23
app.py CHANGED
@@ -1,33 +1,60 @@
1
  import json
2
- from keras.models import Model, load_model
 
3
  import gradio as gr
4
  import cv2
 
5
 
 
 
6
 
7
- model = load_model('final_vgg1920epochs.h5', compile=True)
 
8
 
9
- # Opening JSON file
10
- f = open('dat.json')
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
- img = cv2.resize(image, (32,32)) / 255.0
21
- prediction = model.predict(img.reshape(1,32,32,3))
22
- print(prediction)
23
-
24
-
25
- return keys[prediction.argmax()],data[keys[prediction.argmax()]]['description'],data[keys[prediction.argmax()]]['symptoms'],data[keys[prediction.argmax()]]['causes'],data[keys[prediction.argmax()]]['treatement-1']
26
-
27
- demo=gr.Interface(fn=Predict,
28
- inputs="image",
29
- outputs=[gr.inputs.Textbox(label='Name Of Disease'),gr.inputs.Textbox(label='Description'),gr.inputs.Textbox(label='Symptoms'),gr.inputs.Textbox(label='Causes'),gr.inputs.Textbox(label='Treatement')],
30
- title="Skin Disease Classification",
31
- 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')
32
-
33
- demo.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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)