clementBE commited on
Commit
1a66dd1
Β·
verified Β·
1 Parent(s): f662018

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +84 -81
app.py CHANGED
@@ -189,92 +189,95 @@ with gr.Blocks(title="Qualitative Coding Interface") as demo:
189
  outputs=[full_transcript_text, status_message, current_file_id, coded_data_state]
190
  )
191
 
192
- gr.Markdown("---")
193
- gr.Markdown("## πŸ“ Interview Metadata")
194
-
195
- # Create textboxes for each metadata field
196
- metadata_inputs = []
197
- with gr.Row():
198
- for key, label in METADATA_FIELDS.items():
199
- metadata_inputs.append(gr.Textbox(label=label, value="", max_lines=1, interactive=True))
200
-
201
- gr.Markdown("---")
202
-
203
- # --- B. TRANSCRIPT VIEW ---
204
- gr.Markdown("## πŸ“– Transcript")
205
-
206
- # Display the full text (non-interactive so users copy from it)
207
- transcript_display = gr.Textbox(
208
- label="Transcript Content (Read-only - Copy segments from here)",
209
- lines=15,
210
- interactive=False,
211
- value="",
212
- elem_id="transcript-display"
213
- )
214
- # Update the transcript display whenever the hidden state changes
215
- full_transcript_text.change(lambda x: x, inputs=full_transcript_text, outputs=transcript_display)
216
 
217
- gr.Markdown("---")
218
-
219
- # --- C. CODING/TAGGING CONTROLS ---
220
- gr.Markdown("## 🏷️ Apply Code")
221
- with gr.Row():
222
- segment_input = gr.Textbox(
223
- label="Segment to Code (Paste the text you copied from above)",
224
- lines=3,
225
- scale=3
226
- )
227
- code_dropdown = gr.Dropdown(
228
- label="Select Code/Tag",
229
- choices=DEFAULT_CODES,
230
- scale=1
231
  )
 
 
 
 
232
 
233
- code_btn = gr.Button("Apply Code & Save Segment", variant="primary")
234
-
235
- # --- D. CODED DATA & DOWNLOAD ---
236
- gr.Markdown("---")
237
- gr.Markdown("## πŸ“Š Coded Data")
238
-
239
- # FIX: Removed the 'height=300' argument which caused the TypeError
240
- coded_output_df = gr.Dataframe(
241
- label="Current Coded Segments",
242
- interactive=False,
243
- )
244
- # Update the dataframe display whenever the hidden state changes
245
- coded_data_state.change(lambda x: x, inputs=coded_data_state, outputs=coded_output_df)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
246
 
247
- with gr.Row():
248
- download_btn = gr.Button("Download Codes as XLSX", variant="secondary")
249
- download_file = gr.File(label="Download File", visible=False) # Keep hidden until ready
250
 
251
- # --- E. ACTION BINDINGS ---
252
-
253
- # 1. Apply Code Button Logic
254
- code_btn.click(
255
- fn=apply_code,
256
- inputs=[
257
- coded_data_state,
258
- current_file_id,
259
- full_transcript_text,
260
- segment_input,
261
- code_dropdown,
262
- gr.List(metadata_inputs) # Pass all metadata inputs as a list
263
- ],
264
- outputs=[coded_data_state, status_message]
265
- )
266
-
267
- # 2. Download Button Logic
268
- download_btn.click(
269
- fn=generate_excel,
270
- inputs=coded_data_state,
271
- outputs=[download_file, status_message]
272
- ).then(
273
- # Make the file visible after generation
274
- lambda x: gr.update(visible=True) if x[0] else gr.update(visible=False),
275
- inputs=[download_file],
276
- outputs=[download_file]
277
- )
278
 
279
 
280
  # Launch the app
 
189
  outputs=[full_transcript_text, status_message, current_file_id, coded_data_state]
190
  )
191
 
192
+ # --- MAIN CONTENT COLUMN (FIX) ---
193
+ # Placing the rest of the UI inside a Column ensures proper vertical layout rendering
194
+ with gr.Column():
195
+ gr.Markdown("---")
196
+ gr.Markdown("## πŸ“ Interview Metadata")
197
+
198
+ # Create textboxes for each metadata field
199
+ metadata_inputs = []
200
+ with gr.Row():
201
+ for key, label in METADATA_FIELDS.items():
202
+ metadata_inputs.append(gr.Textbox(label=label, value="", max_lines=1, interactive=True))
 
 
 
 
 
 
 
 
 
 
 
 
 
203
 
204
+ gr.Markdown("---")
205
+
206
+ # --- B. TRANSCRIPT VIEW ---
207
+ gr.Markdown("## πŸ“– Transcript")
208
+
209
+ # Display the full text (non-interactive so users copy from it)
210
+ transcript_display = gr.Textbox(
211
+ label="Transcript Content (Read-only - Copy segments from here)",
212
+ lines=15,
213
+ interactive=False,
214
+ value="",
215
+ elem_id="transcript-display"
 
 
216
  )
217
+ # Update the transcript display whenever the hidden state changes
218
+ full_transcript_text.change(lambda x: x, inputs=full_transcript_text, outputs=transcript_display)
219
+
220
+ gr.Markdown("---")
221
 
222
+ # --- C. CODING/TAGGING CONTROLS ---
223
+ gr.Markdown("## 🏷️ Apply Code")
224
+ with gr.Row():
225
+ segment_input = gr.Textbox(
226
+ label="Segment to Code (Paste the text you copied from above)",
227
+ lines=3,
228
+ scale=3
229
+ )
230
+ code_dropdown = gr.Dropdown(
231
+ label="Select Code/Tag",
232
+ choices=DEFAULT_CODES,
233
+ scale=1
234
+ )
235
+
236
+ code_btn = gr.Button("Apply Code & Save Segment", variant="primary")
237
+
238
+ # --- D. CODED DATA & DOWNLOAD ---
239
+ gr.Markdown("---")
240
+ gr.Markdown("## πŸ“Š Coded Data")
241
+
242
+ # FIX: Removed the 'height=300' argument
243
+ coded_output_df = gr.Dataframe(
244
+ label="Current Coded Segments",
245
+ interactive=False,
246
+ )
247
+ # Update the dataframe display whenever the hidden state changes
248
+ coded_data_state.change(lambda x: x, inputs=coded_data_state, outputs=coded_output_df)
249
 
250
+ with gr.Row():
251
+ download_btn = gr.Button("Download Codes as XLSX", variant="secondary")
252
+ download_file = gr.File(label="Download File", visible=False) # Keep hidden until ready
253
 
254
+ # --- E. ACTION BINDINGS ---
255
+
256
+ # 1. Apply Code Button Logic
257
+ code_btn.click(
258
+ fn=apply_code,
259
+ inputs=[
260
+ coded_data_state,
261
+ current_file_id,
262
+ full_transcript_text,
263
+ segment_input,
264
+ code_dropdown,
265
+ gr.List(metadata_inputs) # Pass all metadata inputs as a list
266
+ ],
267
+ outputs=[coded_data_state, status_message]
268
+ )
269
+
270
+ # 2. Download Button Logic
271
+ download_btn.click(
272
+ fn=generate_excel,
273
+ inputs=coded_data_state,
274
+ outputs=[download_file, status_message]
275
+ ).then(
276
+ # Make the file visible after generation
277
+ lambda x: gr.update(visible=True) if x[0] else gr.update(visible=False),
278
+ inputs=[download_file],
279
+ outputs=[download_file]
280
+ )
281
 
282
 
283
  # Launch the app