Krish30 commited on
Commit
2d972c6
·
verified ·
1 Parent(s): 683c8fb

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ import numpy as np
4
+ import pickle
5
+
6
+ # Load necessary objects from the pickle file
7
+ with open("C:\Users\Administrator\Downloads\model_data_2.pkl" 'rb') as file:
8
+ pickle_data = pickle.load(file)
9
+
10
+ # Load the model
11
+ model = pickle_data['model']
12
+ class_names = ["CLL case lymphocytes", "Normal lymphocytes"]
13
+
14
+ # Define function to preprocess and predict image
15
+ def predict(image):
16
+ img_array = tf.keras.preprocessing.image.img_to_array(image)
17
+ img_array = tf.expand_dims(img_array, 0) # Create a batch of images
18
+
19
+ predictions = model.predict(img_array)
20
+ predicted_class = class_names[np.argmax(predictions[0])]
21
+ confidence = round(100 * np.max(predictions[0]), 2)
22
+
23
+ return predicted_class + f" ({confidence}%)"
24
+
25
+ # Define Gradio Interface
26
+ image = gr.Image(type='pil', label="Upload Image")
27
+ label = gr.Label(label="Predicted Class")
28
+
29
+ gr.Interface(predict, inputs=image, outputs=label, title="Cancer Classification App").launch()