psinha823 commited on
Commit
8ffc381
·
verified ·
1 Parent(s): 238554e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+ import numpy as np
4
+ from PIL import Image
5
+ import tensorflow as tf
6
+
7
+ model_path = r'./model.h5'
8
+
9
+ # Function to preprocess the image and make predictions
10
+ def classify_Lung_and_colon_image(input_image):
11
+ try:
12
+ # Preprocess the image (resize, normalize, etc.)
13
+ input_image = np.array(input_image)
14
+ input_image_copy = input_image.copy() # Making a copy to avoid the array reference issue
15
+ input_image_resized = np.array(Image.fromarray(input_image_copy).resize((224, 224))) / 255.0
16
+ input_image_resized = np.expand_dims(input_image_resized, axis=0)
17
+
18
+ # Making predictions
19
+ model_h5 = tf.keras.models.load_model(model_path)
20
+ predictions = model_h5.predict(input_image_resized)
21
+
22
+ # Getting the class with the highest probability
23
+ class_idx = np.argmax(predictions)
24
+ class_label = ["Colon Adenocarcinoma", "Colon Benign Tissue", "Lung Adenocarcinoma", "Lung Benign Tissue", "Lung Squamous Cell Carcinoma"][class_idx]
25
+ confidence = predictions[0][class_idx]
26
+
27
+ return f"Prediction: {class_label}, Confidence: {confidence:.2f}"
28
+ except Exception as e:
29
+ return str(e)
30
+
31
+ # Creating a Gradio interface
32
+ iface = gr.Interface(
33
+ fn=classify_alzheimers_image,
34
+ inputs="image",
35
+ outputs="text",
36
+ title="Lung and Colon Cancer Detection",
37
+ description=" Upload a Histopathology Image for classification.",
38
+ flagging_options = ["Wrong Prediction"],
39
+ theme = 'darkhuggingface'
40
+ )
41
+
42
+ # Launching the Gradio interface
43
+ iface.launch(inline = False)