hixoop commited on
Commit
ad7bb38
·
verified ·
1 Parent(s): b361621

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -2
app.py CHANGED
@@ -4,6 +4,8 @@ import numpy as np
4
  from PIL import Image
5
  import cv2
6
  import tensorflow as tf
 
 
7
 
8
  model = keras.models.load_model('my_model (2).h5')
9
 
@@ -32,7 +34,20 @@ def make_gradcam_heatmap(img_array, model):
32
  return heatmap.numpy()
33
 
34
  def predict(input_image):
35
- img = Image.fromarray(input_image).convert('RGB')
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  img = img.resize((224, 224))
37
  img_array = np.array(img) / 255.0
38
  img_array = np.expand_dims(img_array, axis=0)
@@ -68,7 +83,8 @@ demo = gr.Interface(
68
  gr.Textbox(label="Classification Result")
69
  ],
70
  title="Bone Cancer Detection (Osteosarcoma)",
71
- description="Upload an H&E stained histopathology image to classify as Non-Tumor, Non-Viable-Tumor, Viable, or viable: non-viable."
 
72
  )
73
 
74
  demo.launch()
 
4
  from PIL import Image
5
  import cv2
6
  import tensorflow as tf
7
+ import base64
8
+ import io
9
 
10
  model = keras.models.load_model('my_model (2).h5')
11
 
 
34
  return heatmap.numpy()
35
 
36
  def predict(input_image):
37
+ # Handle both file upload and base64 string
38
+ if isinstance(input_image, str) and input_image.startswith('data:'):
39
+ # Base64 input
40
+ base64_data = input_image.split(',')[1]
41
+ image_bytes = base64.b64decode(base64_data)
42
+ img = Image.open(io.BytesIO(image_bytes)).convert('RGB')
43
+ elif isinstance(input_image, str):
44
+ # Plain base64 without prefix
45
+ image_bytes = base64.b64decode(input_image)
46
+ img = Image.open(io.BytesIO(image_bytes)).convert('RGB')
47
+ else:
48
+ # Normal image array from Gradio
49
+ img = Image.fromarray(input_image).convert('RGB')
50
+
51
  img = img.resize((224, 224))
52
  img_array = np.array(img) / 255.0
53
  img_array = np.expand_dims(img_array, axis=0)
 
83
  gr.Textbox(label="Classification Result")
84
  ],
85
  title="Bone Cancer Detection (Osteosarcoma)",
86
+ description="Upload an H&E stained histopathology image to classify.",
87
+ api_name="predict"
88
  )
89
 
90
  demo.launch()