anekcb commited on
Commit
4be5153
·
1 Parent(s): b27b528

Delete app (1).py

Browse files
Files changed (1) hide show
  1. app (1).py +0 -50
app (1).py DELETED
@@ -1,50 +0,0 @@
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()