fpessanha commited on
Commit
1924fb2
·
1 Parent(s): 06b95aa

Feat: Add error message with next and previous button; define lets go button

Browse files
Files changed (1) hide show
  1. app.py +15 -37
app.py CHANGED
@@ -79,39 +79,24 @@ def save_annotation(emotions, confidence, comments):
79
 
80
  def next_example(emotions, confidence, comments):
81
  """Move to the next example."""
82
- if emotions == '':
83
- raise gr.Error("Please fill out the emotion section")
84
  else:
85
 
86
  save_annotation(emotions, confidence, comments)
87
  if current_index["index"] < len(file_list) - 1:
88
  current_index["index"] += 1
89
- return load_example(current_index["index"])
90
-
91
- #return "End of examples", None, 0, 0, 0, 0, ''
92
-
93
 
94
  def previous_example(emotion, confidence, comments):
95
  """Move to the previous example."""
96
- save_annotation(emotion, confidence, comments)
97
- if current_index["index"] > 0:
98
- current_index["index"] -= 1
 
 
99
  return load_example(current_index["index"])
100
- return load_example(current_index["index"])
101
-
102
 
103
- def update_progress():
104
-
105
- """Update annotation progress"""
106
- global ann_completed
107
- if ann_completed < total_annotations:
108
- ann_completed += 1
109
-
110
- return f"{ann_completed}/{ total_annotations}"
111
-
112
- def change_visibility(elements):
113
- for el in elements:
114
- el.visible = True
115
 
116
  # ===================
117
  # Gradio Interface
@@ -139,17 +124,16 @@ with (gr.Blocks(theme=gr.themes.Soft(), css = css) as demo):
139
 
140
  # Hidden row with corresponding sentence
141
  with gr.Row():
142
- accordion = gr.Accordion(label="Click to see the sentence", open=False, visible = False)
143
  with accordion:
144
  sentence_text = gr.Textbox(label="Sentence", interactive=False)
145
 
146
  # Row for emotion annotation and confidence
147
  with gr.Row():
148
- emotions = gr.Radio(["Joy", "Sad", "Angry", "Neutral"], label="Predominant Emotion", visible=False)
149
 
150
  with gr.Row():
151
- confidence = gr.Slider(label="Confidence (%)", minimum=0, maximum=100, step=10, visible=False)
152
-
153
  # Instructions for emotion annotation
154
  with gr.Sidebar():
155
  happy_words = gr.Textbox(label = "Happy")
@@ -157,21 +141,15 @@ with (gr.Blocks(theme=gr.themes.Soft(), css = css) as demo):
157
 
158
  # Next and Previous Buttons
159
  with gr.Row():
160
- previous_button = gr.Button("Previous Example", visible=False)
161
- next_button = gr.Button("Next Example", visible=False)
162
 
163
 
164
  # Comment section
165
- comments = gr.Textbox(label="Comments", interactive=True, visible=False)
166
 
167
 
168
 
169
- # Load example
170
- sentence_text.value, audio_player.value, emotions.value, confidence.value, ann_completed.value, comments.value = load_example(
171
- current_index["index"])
172
-
173
-
174
-
175
  # Go back
176
  previous_button.click(
177
  previous_example,
@@ -189,7 +167,7 @@ with (gr.Blocks(theme=gr.themes.Soft(), css = css) as demo):
189
  #Update progress bar
190
  next_button.click(None, [], [ann_completed, total], js = js_progress_bar)
191
 
192
- lets_go.click(change_visibility, inputs = [audio_player, accordion, emotions, confidence, previous_button, next_button, comments], outputs = None)
193
 
194
  demo.launch()
195
 
 
79
 
80
  def next_example(emotions, confidence, comments):
81
  """Move to the next example."""
82
+ if emotions == "Blank":
83
+ raise gr.Warning("Please fill out the emotion section")
84
  else:
85
 
86
  save_annotation(emotions, confidence, comments)
87
  if current_index["index"] < len(file_list) - 1:
88
  current_index["index"] += 1
89
+ return load_example(current_index["index"])
 
 
 
90
 
91
  def previous_example(emotion, confidence, comments):
92
  """Move to the previous example."""
93
+ if emotion.value != "Blank":
94
+ save_annotation(emotion, confidence, comments)
95
+ if current_index["index"] > 0:
96
+ current_index["index"] -= 1
97
+ return load_example(current_index["index"])
98
  return load_example(current_index["index"])
 
 
99
 
 
 
 
 
 
 
 
 
 
 
 
 
100
 
101
  # ===================
102
  # Gradio Interface
 
124
 
125
  # Hidden row with corresponding sentence
126
  with gr.Row():
127
+ accordion = gr.Accordion(label="Click to see the sentence", open=False)
128
  with accordion:
129
  sentence_text = gr.Textbox(label="Sentence", interactive=False)
130
 
131
  # Row for emotion annotation and confidence
132
  with gr.Row():
133
+ emotions = gr.Radio(["Blank", "Joy", "Sad", "Angry", "Neutral"], label="Predominant Emotion", value = "Blank")
134
 
135
  with gr.Row():
136
+ confidence = gr.Slider(label="Confidence (%)", minimum=0, maximum=100, step=10)
 
137
  # Instructions for emotion annotation
138
  with gr.Sidebar():
139
  happy_words = gr.Textbox(label = "Happy")
 
141
 
142
  # Next and Previous Buttons
143
  with gr.Row():
144
+ previous_button = gr.Button("Previous Example")
145
+ next_button = gr.Button("Next Example")
146
 
147
 
148
  # Comment section
149
+ comments = gr.Textbox(label="Comments", interactive=True)
150
 
151
 
152
 
 
 
 
 
 
 
153
  # Go back
154
  previous_button.click(
155
  previous_example,
 
167
  #Update progress bar
168
  next_button.click(None, [], [ann_completed, total], js = js_progress_bar)
169
 
170
+ lets_go.click(load_example, inputs = [gr.Number(current_index["index"], visible = False)], outputs = [sentence_text, audio_playe, emotions, confidence, ann_completed, comments])
171
 
172
  demo.launch()
173