anna-tch commited on
Commit
424cdcc
·
1 Parent(s): ab8cecb

Add application file

Browse files
Files changed (1) hide show
  1. app.py +19 -85
app.py CHANGED
@@ -62,9 +62,7 @@ def get_current_comment(state):
62
  def update_display(state):
63
  example, comment_id = get_current_comment(state)
64
  if not comment_id:
65
- return [gr.update(value="No examples!", visible=False)] + \
66
- [gr.update(visible=False)] * len(state["adapter_columns"]) * 4 + \
67
- [gr.update(value="Complete!"), state]
68
 
69
  existing_annotation = {}
70
  if example['manual_annotation']:
@@ -75,11 +73,9 @@ def update_display(state):
75
  text = example.get(adapter, "")
76
  scores = existing_annotation.get(adapter, {}) if existing_annotation else {}
77
  updates.extend([
78
- gr.update(value=text, visible=True), # Text display
79
- gr.update(visible=True), # Grammar title
80
- gr.update(value=scores.get("grammar"), visible=True), # Grammar score
81
- gr.update(visible=True), # Coherence title
82
- gr.update(value=scores.get("coherence"), visible=True) # Coherence score
83
  ])
84
 
85
  return updates + [
@@ -87,30 +83,6 @@ def update_display(state):
87
  state
88
  ]
89
 
90
- # def update_display(state):
91
- # example, comment_id = get_current_comment(state)
92
- # if not comment_id:
93
- # return [gr.update(value="No examples!")] + [gr.update(visible=False)] * len(state["adapter_columns"]) * 3 + [gr.update(value="Complete!"), state]
94
-
95
- # existing_annotation = {}
96
- # if example['manual_annotation']:
97
- # existing_annotation = json.loads(example['manual_annotation'])
98
-
99
- # updates = []
100
- # for adapter in state["adapter_columns"]:
101
- # text = example.get(adapter, "")
102
- # scores = existing_annotation.get(adapter, {}) if existing_annotation else {}
103
- # updates.extend([
104
- # gr.update(value=text, visible=True),
105
- # gr.update(value=scores.get("grammar"), visible=True),
106
- # gr.update(value=scores.get("coherence"), visible=True)
107
- # ])
108
-
109
- # return updates + [
110
- # gr.update(value=f"Example {state['current_id_index'] + 1} of {len(state[state['current_view'] + '_ids'])} ({state['current_view']})"),
111
- # state
112
- # ]
113
-
114
  def navigate(direction, state):
115
  ids = state[state["current_view"] + "_ids"]
116
  max_index = len(ids) - 1
@@ -163,70 +135,32 @@ def submit(*args):
163
 
164
  return navigate("next", state)
165
 
166
- # with gr.Blocks() as app:
167
- # state = gr.State(load_data())
168
-
169
- # gr.Markdown("## Text Annotation Tool")
170
-
171
- # with gr.Row():
172
- # # Sidebar Column
173
- # with gr.Column(scale=1, min_width=200, elem_classes="sidebar"):
174
- # gr.Markdown("### Navigation")
175
- # with gr.Column(elem_classes="nav-buttons"):
176
- # annotated_btn = gr.Button("Annotated", variant="primary")
177
- # unannotated_btn = gr.Button("Unannotated", variant="primary")
178
- # gr.Markdown("---")
179
- # counter = gr.Markdown()
180
-
181
- # # Main Content Column
182
- # with gr.Column(scale=4):
183
- # adapter_components = []
184
- # for adapter in state.value["adapter_columns"]:
185
- # with gr.Row():
186
- # adapter_components.extend([
187
- # gr.Textbox(label=f"{adapter} Output", visible=False, interactive=False),
188
- # gr.Radio(choices=[1, 2, 3, 4, 5], label=f"{adapter} Grammar", visible=False),
189
- # gr.Radio(choices=[1, 2, 3, 4, 5], label=f"{adapter} Coherence", visible=False)
190
- # ])
191
- # gr.Markdown("---")
192
-
193
- # with gr.Row():
194
- # prev_btn = gr.Button("Previous", variant="secondary")
195
- # next_btn = gr.Button("Next", variant="secondary")
196
- # submit_btn = gr.Button("Submit", variant="primary")
197
-
198
  with gr.Blocks() as app:
199
  state = gr.State(load_data())
200
 
201
  gr.Markdown("## Text Annotation Tool")
202
 
203
  with gr.Row():
204
- # Sidebar Column (keep this the same)
 
 
 
 
 
 
 
205
 
206
  # Main Content Column
207
  with gr.Column(scale=4):
208
  adapter_components = []
209
  for adapter in state.value["adapter_columns"]:
210
  with gr.Row():
211
- adapter_components.append(
212
- gr.Textbox(label=f"{adapter} Output", visible=False, interactive=False)
213
- )
214
- with gr.Row():
215
- with gr.Column():
216
- adapter_components.append(
217
- gr.Markdown("### Grammar Score", visible=False)
218
- )
219
- adapter_components.append(
220
- gr.Radio(choices=[1, 2, 3, 4, 5], label="", visible=False)
221
- )
222
- with gr.Column():
223
- adapter_components.append(
224
- gr.Markdown("### Coherence Score", visible=False)
225
- )
226
- adapter_components.append(
227
- gr.Radio(choices=[1, 2, 3, 4, 5], label="", visible=False)
228
- )
229
- gr.Markdown("---", visible=False)
230
 
231
  with gr.Row():
232
  prev_btn = gr.Button("Previous", variant="secondary")
@@ -267,7 +201,7 @@ with gr.Blocks() as app:
267
 
268
  submit_btn.click(
269
  submit,
270
- inputs=adapter_components[2::4] + adapter_components[4::4] + [state], # Get every 4th component starting at index 2 and 4
271
  outputs=navigation_outputs
272
  )
273
 
 
62
  def update_display(state):
63
  example, comment_id = get_current_comment(state)
64
  if not comment_id:
65
+ return [gr.update(value="No examples!")] + [gr.update(visible=False)] * len(state["adapter_columns"]) * 3 + [gr.update(value="Complete!"), state]
 
 
66
 
67
  existing_annotation = {}
68
  if example['manual_annotation']:
 
73
  text = example.get(adapter, "")
74
  scores = existing_annotation.get(adapter, {}) if existing_annotation else {}
75
  updates.extend([
76
+ gr.update(value=text, visible=True),
77
+ gr.update(value=scores.get("grammar"), visible=True),
78
+ gr.update(value=scores.get("coherence"), visible=True)
 
 
79
  ])
80
 
81
  return updates + [
 
83
  state
84
  ]
85
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  def navigate(direction, state):
87
  ids = state[state["current_view"] + "_ids"]
88
  max_index = len(ids) - 1
 
135
 
136
  return navigate("next", state)
137
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
138
  with gr.Blocks() as app:
139
  state = gr.State(load_data())
140
 
141
  gr.Markdown("## Text Annotation Tool")
142
 
143
  with gr.Row():
144
+ # Sidebar Column
145
+ with gr.Column(scale=1, min_width=200, elem_classes="sidebar"):
146
+ gr.Markdown("### Navigation")
147
+ with gr.Column(elem_classes="nav-buttons"):
148
+ annotated_btn = gr.Button("Annotated", variant="primary")
149
+ unannotated_btn = gr.Button("Unannotated", variant="primary")
150
+ gr.Markdown("---")
151
+ counter = gr.Markdown()
152
 
153
  # Main Content Column
154
  with gr.Column(scale=4):
155
  adapter_components = []
156
  for adapter in state.value["adapter_columns"]:
157
  with gr.Row():
158
+ adapter_components.extend([
159
+ gr.Textbox(label=f"{adapter} Output", visible=False, interactive=False),
160
+ gr.Radio(choices=[1, 2, 3, 4, 5], label=f"Grammar", visible=False),
161
+ gr.Radio(choices=[1, 2, 3, 4, 5], label=f"Coherence", visible=False)
162
+ ])
163
+ gr.Markdown("---")
 
 
 
 
 
 
 
 
 
 
 
 
 
164
 
165
  with gr.Row():
166
  prev_btn = gr.Button("Previous", variant="secondary")
 
201
 
202
  submit_btn.click(
203
  submit,
204
+ inputs=adapter_components[1::3] + adapter_components[2::3] + [state],
205
  outputs=navigation_outputs
206
  )
207