DocUA commited on
Commit
f181eed
·
1 Parent(s): d6c841d

Fix Gradio 6.x Button '_id' attribute error in verification UI

Browse files

- Changed gr.Blocks() pattern to 'with gr.Blocks() as interface'
- Pre-compute initial values before Blocks context
- Define event handlers before Blocks context
- Pass initial values directly to component constructors
- Add cancel_correction_btn handler

src/interface/conversation_verification_ui.py CHANGED
@@ -37,11 +37,37 @@ class VerificationInterface:
37
  """
38
  self.current_session = session
39
  self.current_record_index = 0
 
 
 
 
 
 
 
 
 
 
 
 
40
 
41
- # Create interface without theme for HF Spaces compatibility
42
- interface = gr.Blocks(title=f"Verify Conversation - {session.patient_name}")
 
 
 
 
43
 
44
- with interface:
 
 
 
 
 
 
 
 
 
 
45
 
46
  # Session header
47
  with gr.Row():
@@ -56,19 +82,19 @@ class VerificationInterface:
56
 
57
  # Progress section
58
  with gr.Row():
59
- progress_bar = gr.HTML(value=self._render_progress_bar(session))
60
 
61
  with gr.Row():
62
  with gr.Column(scale=1):
63
- stats_display = gr.HTML(value=self._render_statistics(session))
64
  with gr.Column(scale=1):
65
- navigation_info = gr.HTML(value=self._render_navigation_info(session))
66
 
67
  # Main verification area
68
  with gr.Row():
69
  with gr.Column(scale=3):
70
  # Current exchange display
71
- exchange_display = gr.HTML(value="", label="Current Exchange")
72
 
73
  # Verification buttons
74
  with gr.Row():
@@ -116,7 +142,7 @@ class VerificationInterface:
116
  prev_btn = gr.Button("⬅️ Previous", scale=1)
117
  next_btn = gr.Button("Next ➡️", scale=1)
118
 
119
- current_position = gr.HTML(value="Exchange 1 of 1")
120
 
121
  # Quick actions
122
  gr.Markdown("### Quick Actions")
@@ -130,51 +156,28 @@ class VerificationInterface:
130
  gr.Markdown("### Export Results")
131
  export_btn = gr.Button("📊 Export to CSV", variant="primary")
132
  export_status = gr.HTML(value="")
133
-
134
- # Initialize interface with first exchange data
135
- if session.verification_records:
136
- initial_exchange_html = self._render_exchange_review(session.verification_records[0])
137
- initial_position_html = f"Exchange 1 of {len(session.verification_records)}"
138
- initial_stats_html = self._render_statistics(session)
139
- initial_progress_html = self._render_progress_bar(session)
140
-
141
- exchange_display.value = initial_exchange_html
142
- current_position.value = initial_position_html
143
- stats_display.value = initial_stats_html
144
- progress_bar.value = initial_progress_html
145
- else:
146
- exchange_display.value = "No exchanges to verify"
147
- current_position.value = "No exchanges"
148
-
149
- # Event handlers - simplified for HF Spaces compatibility
150
- def handle_correct_click():
151
- return self._handle_correct_feedback_simple()
152
 
 
153
  correct_btn.click(
154
  fn=handle_correct_click,
155
  outputs=[exchange_display, current_position, stats_display, progress_bar]
156
  )
157
 
158
- def show_correction_section():
159
- return gr.update(visible=True)
160
-
161
  incorrect_btn.click(
162
  fn=show_correction_section,
163
  outputs=[correction_section]
164
  )
165
 
166
- def handle_export_click():
167
- return self._export_results_simple()
 
 
168
 
169
  export_btn.click(
170
  fn=handle_export_click,
171
  outputs=[export_status]
172
  )
173
 
174
- # Simplified handlers for basic functionality
175
- def handle_mark_all_correct():
176
- return self._mark_all_remaining_correct_simple()
177
-
178
  mark_all_correct_btn.click(
179
  fn=handle_mark_all_correct,
180
  outputs=[exchange_display, current_position, stats_display, progress_bar]
 
37
  """
38
  self.current_session = session
39
  self.current_record_index = 0
40
+
41
+ # Pre-compute initial values
42
+ if session.verification_records:
43
+ initial_exchange_html = self._render_exchange_review(session.verification_records[0])
44
+ initial_position_html = f"Exchange 1 of {len(session.verification_records)}"
45
+ else:
46
+ initial_exchange_html = "No exchanges to verify"
47
+ initial_position_html = "No exchanges"
48
+
49
+ initial_stats_html = self._render_statistics(session)
50
+ initial_progress_html = self._render_progress_bar(session)
51
+ initial_nav_html = self._render_navigation_info(session)
52
 
53
+ # Define event handlers before creating the interface
54
+ def handle_correct_click():
55
+ return self._handle_correct_feedback_simple()
56
+
57
+ def show_correction_section():
58
+ return gr.update(visible=True)
59
 
60
+ def hide_correction_section():
61
+ return gr.update(visible=False)
62
+
63
+ def handle_export_click():
64
+ return self._export_results_simple()
65
+
66
+ def handle_mark_all_correct():
67
+ return self._mark_all_remaining_correct_simple()
68
+
69
+ # Create interface without theme for HF Spaces compatibility
70
+ with gr.Blocks(title=f"Verify Conversation - {session.patient_name}") as interface:
71
 
72
  # Session header
73
  with gr.Row():
 
82
 
83
  # Progress section
84
  with gr.Row():
85
+ progress_bar = gr.HTML(value=initial_progress_html)
86
 
87
  with gr.Row():
88
  with gr.Column(scale=1):
89
+ stats_display = gr.HTML(value=initial_stats_html)
90
  with gr.Column(scale=1):
91
+ navigation_info = gr.HTML(value=initial_nav_html)
92
 
93
  # Main verification area
94
  with gr.Row():
95
  with gr.Column(scale=3):
96
  # Current exchange display
97
+ exchange_display = gr.HTML(value=initial_exchange_html, label="Current Exchange")
98
 
99
  # Verification buttons
100
  with gr.Row():
 
142
  prev_btn = gr.Button("⬅️ Previous", scale=1)
143
  next_btn = gr.Button("Next ➡️", scale=1)
144
 
145
+ current_position = gr.HTML(value=initial_position_html)
146
 
147
  # Quick actions
148
  gr.Markdown("### Quick Actions")
 
156
  gr.Markdown("### Export Results")
157
  export_btn = gr.Button("📊 Export to CSV", variant="primary")
158
  export_status = gr.HTML(value="")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
159
 
160
+ # Wire up event handlers
161
  correct_btn.click(
162
  fn=handle_correct_click,
163
  outputs=[exchange_display, current_position, stats_display, progress_bar]
164
  )
165
 
 
 
 
166
  incorrect_btn.click(
167
  fn=show_correction_section,
168
  outputs=[correction_section]
169
  )
170
 
171
+ cancel_correction_btn.click(
172
+ fn=hide_correction_section,
173
+ outputs=[correction_section]
174
+ )
175
 
176
  export_btn.click(
177
  fn=handle_export_click,
178
  outputs=[export_status]
179
  )
180
 
 
 
 
 
181
  mark_all_correct_btn.click(
182
  fn=handle_mark_all_correct,
183
  outputs=[exchange_display, current_position, stats_display, progress_bar]