Dor-Hac commited on
Commit
ae08ded
1 Parent(s): ae43236

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +12 -16
app.py CHANGED
@@ -12,23 +12,19 @@ model = load_model('melanoma_cancer_model.h5')
12
 
13
  # Define the function to make predictions
14
  def classify_image(img):
15
- img = np.array(img)
16
  img = np.expand_dims(img, axis=0)
17
- img = img/255
18
- # Resize data for the model (128, 128,3)
19
- resized_img = tf.image.resize(img, [128, 128])
20
-
21
- prediction = model.predict(resized_img)
22
- print(prediction)
23
- # return melanuma or not melanoma
24
- return {"melanoma": prediction[0][0], "not melanoma": 1 - prediction[0][0]}
25
 
26
 
27
- #image = gr.Image(shape=(128, 128), type='pil', image_mode='RGB')
28
- #label = gr.Label(num_top_classes=2)
29
-
30
- # Run on localhost
31
- gr.Interface(fn=classify_image, inputs="image", outputs="label").launch()
32
- #gr.Interface(fn=classify_image, inputs=image, outputs=label).launch(server_port=7860)
33
 
34
- # Run the app
 
12
 
13
  # Define the function to make predictions
14
  def classify_image(img):
 
15
  img = np.expand_dims(img, axis=0)
16
+ # Resize image
17
+ resized_img = tf.image.resize(img, [160, 160])
18
+ # Predict the image
19
+ prediction = model.predict(resized_img)[0][0]
20
+ # Convert to float value
21
+ prediction = float(prediction)
22
+ # return dictionary for Gradio
23
+ return {"melanoma": prediction, "not melanoma": 1 - prediction}
24
 
25
 
26
+ # Launch the Gradio interface
27
+ gr.Interface(fn=classify_image, inputs='image', outputs="label").launch()
28
+ # Launch shareble Gradio interface
29
+ # gr.Interface(fn=classify_image, inputs='image', outputs="label").launch(share=True)
 
 
30