AyobamiMichael commited on
Commit
ab151ed
·
verified ·
1 Parent(s): e54758c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -5
app.py CHANGED
@@ -98,6 +98,7 @@ def load_model():
98
  model.eval()
99
  return model
100
 
 
101
  def load_class_names():
102
  with open(config.CLASS_NAMES_PATH, "r") as f:
103
  return json.load(f)
@@ -151,6 +152,7 @@ class GradCAM:
151
  cam = cam / (cam.max() + 1e-8)
152
  return cam.cpu().numpy()
153
 
 
154
  def overlay_heatmap(image, heatmap):
155
  image = np.array(image.resize((config.IMAGE_SIZE, config.IMAGE_SIZE)))
156
  heatmap = cv2.resize(heatmap, (image.shape[1], image.shape[0]))
@@ -252,18 +254,32 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo:
252
  )
253
 
254
  with gr.Row():
 
255
  with gr.Column():
256
- with gr.Box(elem_classes=["section-card"]):
257
- input_image = gr.Image(type="pil", label="Upload Image", height=380)
258
- classify_btn = gr.Button("Run Classification", variant="primary")
 
 
 
 
 
 
 
259
 
260
  with gr.Column():
261
  with gr.Tab("Results"):
262
- predictions = gr.Label(label="Top Predictions", num_top_classes=3)
 
 
 
263
  recycling_info = gr.Markdown()
264
 
265
  with gr.Tab("Model Interpretation"):
266
- heatmap = gr.Image(label="Grad-CAM Visualization", height=380)
 
 
 
267
 
268
  classify_btn.click(
269
  classify_image,
 
98
  model.eval()
99
  return model
100
 
101
+
102
  def load_class_names():
103
  with open(config.CLASS_NAMES_PATH, "r") as f:
104
  return json.load(f)
 
152
  cam = cam / (cam.max() + 1e-8)
153
  return cam.cpu().numpy()
154
 
155
+
156
  def overlay_heatmap(image, heatmap):
157
  image = np.array(image.resize((config.IMAGE_SIZE, config.IMAGE_SIZE)))
158
  heatmap = cv2.resize(heatmap, (image.shape[1], image.shape[0]))
 
254
  )
255
 
256
  with gr.Row():
257
+
258
  with gr.Column():
259
+ with gr.Group(elem_classes=["section-card"]):
260
+ input_image = gr.Image(
261
+ type="pil",
262
+ label="Upload Image",
263
+ height=380
264
+ )
265
+ classify_btn = gr.Button(
266
+ "Run Classification",
267
+ variant="primary"
268
+ )
269
 
270
  with gr.Column():
271
  with gr.Tab("Results"):
272
+ predictions = gr.Label(
273
+ label="Top Predictions",
274
+ num_top_classes=3
275
+ )
276
  recycling_info = gr.Markdown()
277
 
278
  with gr.Tab("Model Interpretation"):
279
+ heatmap = gr.Image(
280
+ label="Grad-CAM Visualization",
281
+ height=380
282
+ )
283
 
284
  classify_btn.click(
285
  classify_image,