elibrowne commited on
Commit
2b0e5c7
·
1 Parent(s): 2307e61

Collapsible?

Browse files
Files changed (1) hide show
  1. app.py +24 -62
app.py CHANGED
@@ -36,6 +36,28 @@ qa_data = load_dataset("ebrowne/test-data", data_files = "test.json")
36
  q = qa_data["train"][0] # loaded question data
37
  """
38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  # VARIABLES: will eventually be loaded with JSON from a dataset
40
 
41
  """
@@ -117,71 +139,11 @@ with gr.Blocks() as user_eval:
117
  step += 1
118
  print(eval_1 + eval_2 + eval_3)
119
  if step == len(passage_texts):
120
- collapsible_string = """
121
- <style>
122
- /* Style the button that is used to open and close the collapsible content */
123
- .collapsible {
124
- background-color: #eee;
125
- color: #444;
126
- cursor: pointer;
127
- padding: 18px;
128
- width: 100%;
129
- border: none;
130
- text-align: left;
131
- outline: none;
132
- font-size: 15px;
133
- }
134
- .collapsible:after {
135
- content: '\02795'; /* Unicode character for "plus" sign (+) */
136
- font-size: 13px;
137
- color: white;
138
- float: right;
139
- margin-left: 5px;
140
- }
141
-
142
- .active:after {
143
- content: "\2796"; /* Unicode character for "minus" sign (-) */
144
- }
145
-
146
- /* Add a background color to the button if it is clicked on (add the .active class with JS), and when you move the mouse over it (hover) */
147
- .active, .collapsible:hover {
148
- background-color: #ccc;
149
- }
150
-
151
- /* Style the collapsible content. Note: hidden by default */
152
- .content {
153
- padding: 0 18px;
154
- display: none;
155
- overflow: hidden;
156
- background-color: #f1f1f1;
157
- }
158
- </style>
159
- """
160
  for i, passage in enumerate(passage_texts):
161
  collapsible_string += """
162
- <button type="button" class="collapsible">Passage """ + str(i + 1) + """</button>
163
- <div class="content">
164
  <p> """ + passage + """ </p>
165
- </div>
166
  """
167
- collapsible_string += """
168
- <script>
169
- var coll = document.getElementsByClassName("collapsible");
170
- var i;
171
-
172
- for (i = 0; i < coll.length; i++) {
173
- coll[i].addEventListener("click", function() {
174
- this.classList.toggle("active");
175
- var content = this.nextElementSibling;
176
- if (content.style.display === "block") {
177
- content.style.display = "none";
178
- } else {
179
- content.style.display = "block";
180
- }
181
- });
182
- }
183
- </script>
184
- """
185
  return {
186
  selection: gr.HTML(collapsible_string),
187
  scores_p: gr.Column(visible = False),
@@ -245,6 +207,6 @@ with gr.Blocks() as user_eval:
245
  s.click(fn = submit_email, inputs = [email], outputs = [question, login])
246
 
247
  # Starts on question, switches to evaluation after the user answers
248
- user_eval.launch()
249
 
250
  # https://github.com/gradio-app/gradio/issues/5791
 
36
  q = qa_data["train"][0] # loaded question data
37
  """
38
 
39
+ # JAVASCRIPT: for collapsible
40
+ js = """
41
+ async () => {
42
+ addCollapsible = () => {
43
+ var coll = document.getElementsByClassName("collapsible");
44
+ var i;
45
+
46
+ for (i = 0; i < coll.length; i++) {
47
+ coll[i].addEventListener("click", function() {
48
+ this.classList.toggle("active");
49
+ var content = this.nextElementSibling;
50
+ if (content.style.display === "block") {
51
+ content.style.display = "none";
52
+ } else {
53
+ content.style.display = "block";
54
+ }
55
+ });
56
+ }
57
+ }
58
+ }
59
+ """
60
+
61
  # VARIABLES: will eventually be loaded with JSON from a dataset
62
 
63
  """
 
139
  step += 1
140
  print(eval_1 + eval_2 + eval_3)
141
  if step == len(passage_texts):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
142
  for i, passage in enumerate(passage_texts):
143
  collapsible_string += """
144
+ <strong>Passage """ + str(i + 1) + """</strong>
 
145
  <p> """ + passage + """ </p>
 
146
  """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147
  return {
148
  selection: gr.HTML(collapsible_string),
149
  scores_p: gr.Column(visible = False),
 
207
  s.click(fn = submit_email, inputs = [email], outputs = [question, login])
208
 
209
  # Starts on question, switches to evaluation after the user answers
210
+ user_eval.launch(js = js)
211
 
212
  # https://github.com/gradio-app/gradio/issues/5791