anekcb commited on
Commit
fcf7b2e
·
1 Parent(s): 0756e91

Upload 5 files

Browse files
Files changed (5) hide show
  1. README.md +12 -0
  2. app (1).py +50 -0
  3. keras_model.h5 +3 -0
  4. labels (1).txt +6 -0
  5. requirements.txt +5 -0
README.md ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Bee4Med
3
+ emoji: 📈
4
+ colorFrom: red
5
+ colorTo: blue
6
+ sdk: gradio
7
+ sdk_version: 3.27.0
8
+ app_file: app.py
9
+ pinned: false
10
+ ---
11
+
12
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app (1).py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ from tensorflow.keras.applications.mobilenet_v2 import preprocess_input
4
+ from tensorflow.keras.models import load_model
5
+ from tensorflow.keras.preprocessing import image
6
+ import numpy as np
7
+ from PIL import Image
8
+
9
+
10
+ # Load the model
11
+ model = load_model("keras_model.h5", compile=False)
12
+
13
+ # Load the labels
14
+ class_names = open("labels.txt", "r").readlines()
15
+
16
+
17
+ def predict_image(img):
18
+ # Resize the image
19
+ img = Image.fromarray(img.astype('uint8'), 'RGB')
20
+ img = img.resize((224, 224), resample=Image.BILINEAR)
21
+
22
+ # Preprocess the image
23
+ img_array = image.img_to_array(img)
24
+ img_array = preprocess_input(img_array)
25
+
26
+ # Expand the dimensions to create a batch of size 1
27
+ img_batch = tf.expand_dims(img_array, axis=0)
28
+
29
+ # Predict the class probabilities
30
+ preds = model.predict(img_batch)
31
+ class_idx = tf.argmax(preds, axis=1)[0]
32
+ class_name = class_names[class_idx].strip()
33
+ confidence_score = float(preds[0][class_idx]) # convert to float
34
+
35
+ if class_idx == 5:
36
+ return "We couldn't detect anything from this image. Please try with a different image."
37
+ elif confidence_score >= 0.70:
38
+ return f"There is a {confidence_score*100:.2f}% chance for this image to be {class_name}. Even though it has good accuracy, please consult a doctor for confirmation."
39
+ elif 0.50 <= confidence_score < 0.70:
40
+ return f"There is a {confidence_score*100:.2f}% chance for this image to be {class_name}, but considering the accuracy, it's better to consult a doctor before using our service."
41
+ else:
42
+ return f"There is a {confidence_score*100:.2f}% chance for this image to be {class_name}. Since the accuracy is very low, please consider a doctor's advice and we recommend you not to rely on our predictions."
43
+
44
+
45
+ # Launch the Gradio interface
46
+ iface = gr.Interface(fn=predict_image, inputs="image", outputs="text", title="Bee4Med - Skin Disease Classifier",
47
+ description="This is a machine learning model that predicts skin disease from an image(limited dataset). However, please note that there are chances that the predictions may go wrong, and we strongly recommend you to consult a doctor for confirmation.")
48
+
49
+ # Launch the interface
50
+ iface.launch()
keras_model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:06b9e2bcfc346e8b68e32ac48b39b4686824e09fec2ce124fe15ff7eb2f4dc81
3
+ size 2457008
labels (1).txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ Acne and Rosacea
2
+ Atopic Dermatitis
3
+ Bullous Disease
4
+ Eczema
5
+ alopecia,Fungus and other Nail Disease
6
+ Not able to detect
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ numpy
2
+ gradio
3
+ numpy
4
+ opencv-python-headless
5
+ tensorflow