rishabh5752 commited on
Commit
b225b16
1 Parent(s): d5cf0b4

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -0
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ from tensorflow.keras.models import load_model
4
+ from PIL import Image
5
+
6
+ # Load the trained model
7
+ model = load_model('skin_model.h5')
8
+
9
+ # Define a function to make predictions
10
+ def predict(name, age, image):
11
+ # Preprocess the image
12
+ image = Image.fromarray(image)
13
+ image = image.resize((150, 150))
14
+ image = np.array(image) / 255.0
15
+ image = np.expand_dims(image, axis=0)
16
+
17
+ # Make a prediction using the model
18
+ prediction = model.predict(image)
19
+
20
+ # Get the predicted class label
21
+ if prediction[0][0] < 0.5:
22
+ label = 'Benign'
23
+ else:
24
+ label = 'Malignant'
25
+
26
+ return f"Patient: {name}, Age: {age}, Prediction: {label}"
27
+
28
+ # Define input and output components
29
+ name_input = gr.inputs.Text(label="Patient's Name")
30
+ age_input = gr.inputs.Text(label="Patient's Age")
31
+ image_input = gr.inputs.Image(shape=(150, 150))
32
+ label_output = gr.outputs.Label()
33
+
34
+ # Define a Gradio interface for user interaction
35
+ iface = gr.Interface(
36
+ fn=predict,
37
+ inputs=[name_input, age_input, image_input],
38
+ outputs=label_output,
39
+ title="Skin Cancer Classification Chatbot",
40
+ description="Predicts whether a skin image is cancerous or not based on patient's name, age, and lesion image.",
41
+ theme="default", # Choose a theme: "default", "compact", "huggingface"
42
+ layout="vertical", # Choose a layout: "vertical", "horizontal", "double"
43
+ live=False # Set to True for live updates without clicking "Submit"
44
+ )
45
+
46
+ iface.launch()