huy-ha commited on
Commit
7aa3400
1 Parent(s): 9eae628

swap matplotlib backend and use tag

Browse files
Files changed (1) hide show
  1. app.py +25 -3
app.py CHANGED
@@ -5,6 +5,19 @@ from time import time
5
  from matplotlib import pyplot as plt
6
  import io
7
  from PIL import Image, ImageDraw, ImageFont
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
 
10
  def plot_to_png(fig):
@@ -59,7 +72,10 @@ def generate_relevancy(
59
  )[0]
60
  except Exception as e:
61
  print(e)
62
- return [img]
 
 
 
63
  print("inference took", float(time() - start))
64
  if subtract_mean:
65
  grads -= grads.mean(axis=0)
@@ -85,7 +101,10 @@ def generate_relevancy(
85
  plt.tight_layout(pad=0)
86
  returns.append(plot_to_png(fig))
87
  plt.close(fig)
88
- return returns
 
 
 
89
 
90
 
91
  iface = gr.Interface(
@@ -108,7 +127,10 @@ This relevancy extractor builds heavily on [Chefer et al.'s codebase](https://gi
108
  ),
109
  gr.Checkbox(value=True, label="subtract mean"),
110
  ],
111
- outputs=gr.Gallery(label="Relevancy Maps", type="numpy"),
 
 
 
112
  examples=[
113
  [
114
  "https://semantic-abstraction.cs.columbia.edu/downloads/gameroom.png",
 
5
  from matplotlib import pyplot as plt
6
  import io
7
  from PIL import Image, ImageDraw, ImageFont
8
+ import matplotlib
9
+
10
+ matplotlib.use("Agg")
11
+
12
+ tag = """
13
+ <script async src="https://www.googletagmanager.com/gtag/js?id=G-T5BQ1GP083"></script>
14
+ <script>
15
+ window.dataLayer = window.dataLayer || [];
16
+ function gtag(){dataLayer.push(arguments);}
17
+ gtag('js', new Date());
18
+
19
+ gtag('config', 'G-T5BQ1GP083');
20
+ </script>"""
21
 
22
 
23
  def plot_to_png(fig):
 
72
  )[0]
73
  except Exception as e:
74
  print(e)
75
+ return (
76
+ [img],
77
+ tag,
78
+ )
79
  print("inference took", float(time() - start))
80
  if subtract_mean:
81
  grads -= grads.mean(axis=0)
 
101
  plt.tight_layout(pad=0)
102
  returns.append(plot_to_png(fig))
103
  plt.close(fig)
104
+ return (
105
+ returns,
106
+ tag,
107
+ )
108
 
109
 
110
  iface = gr.Interface(
 
127
  ),
128
  gr.Checkbox(value=True, label="subtract mean"),
129
  ],
130
+ outputs=[
131
+ gr.Gallery(label="Relevancy Maps", type="numpy"),
132
+ gr.HTML(value=tag),
133
+ ],
134
  examples=[
135
  [
136
  "https://semantic-abstraction.cs.columbia.edu/downloads/gameroom.png",