taesiri commited on
Commit
a4e6581
1 Parent(s): c6252e6

Updated Gradio

Browse files
app.py CHANGED
@@ -1,12 +1,16 @@
 
 
 
1
  import torch
 
 
2
  from matplotlib import pyplot as plt
3
- from PIL import Image
4
- import numpy as np
5
  from numpy import matlib as mb
6
- import torchvision.transforms as transforms
7
- import torchvision.models as models
8
- import skimage.transform
9
- import gradio as gr
 
10
 
11
 
12
  def compute_spatial_similarity(conv1, conv2):
@@ -90,13 +94,13 @@ def visualize_similarities(image1, image2):
90
  fig, axes = plt.subplots(1, 2, figsize=(12, 5))
91
  axes[0].imshow(display_transform(image1))
92
  im1 = axes[0].imshow(
93
- skimage.transform.resize(sim1, (224, 224)), alpha=0.6, cmap="jet"
94
  )
95
  # axes[0].colorbar()
96
 
97
  axes[1].imshow(display_transform(image2))
98
  im2 = axes[1].imshow(
99
- skimage.transform.resize(sim2, (224, 224)), alpha=0.6, cmap="jet"
100
  )
101
  # axes[1].colorbar()
102
 
@@ -110,10 +114,19 @@ def visualize_similarities(image1, image2):
110
  iface = gr.Interface(
111
  fn=visualize_similarities,
112
  inputs=[
113
- gr.inputs.Image(shape=(300, 300), type="pil"),
114
- gr.inputs.Image(shape=(300, 300), type="pil"),
 
 
 
 
 
 
 
 
 
 
115
  ],
116
- outputs=[gr.outputs.Plot(type="matplotlib")],
117
  )
118
 
119
  iface.launch()
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ import skimage.transform
4
  import torch
5
+ import torchvision.models as models
6
+ import torchvision.transforms as transforms
7
  from matplotlib import pyplot as plt
 
 
8
  from numpy import matlib as mb
9
+ from PIL import Image
10
+ import csv
11
+ import sys
12
+
13
+ csv.field_size_limit(sys.maxsize)
14
 
15
 
16
  def compute_spatial_similarity(conv1, conv2):
 
94
  fig, axes = plt.subplots(1, 2, figsize=(12, 5))
95
  axes[0].imshow(display_transform(image1))
96
  im1 = axes[0].imshow(
97
+ skimage.transform.resize(sim1, (224, 224)), alpha=0.5, cmap="jet"
98
  )
99
  # axes[0].colorbar()
100
 
101
  axes[1].imshow(display_transform(image2))
102
  im2 = axes[1].imshow(
103
+ skimage.transform.resize(sim2, (224, 224)), alpha=0.5, cmap="jet"
104
  )
105
  # axes[1].colorbar()
106
 
 
114
  iface = gr.Interface(
115
  fn=visualize_similarities,
116
  inputs=[
117
+ gr.Image(type="pil"),
118
+ gr.Image(type="pil"),
119
+ ],
120
+ allow_flagging="never",
121
+ outputs=[gr.Plot(type="matplotlib")],
122
+ cache_examples=True,
123
+ enable_queue=False,
124
+ examples=[
125
+ [
126
+ "./examples/Red_Winged_Blackbird_0012_6015.jpg",
127
+ "./examples/Red_Winged_Blackbird_0025_5342.jpg",
128
+ ]
129
  ],
 
130
  )
131
 
132
  iface.launch()
examples/Red_Winged_Blackbird_0012_6015.jpg ADDED
examples/Red_Winged_Blackbird_0025_5342.jpg ADDED