Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 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 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
choices=DEFAULT_CODES,
|
| 230 |
-
scale=1
|
| 231 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 232 |
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 246 |
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 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
|