clementBE commited on
Commit
561b9c4
·
verified ·
1 Parent(s): 9433a59

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -12
app.py CHANGED
@@ -67,7 +67,8 @@ def get_initial_df():
67
  def process_file(file_obj):
68
  """Handles file upload and returns the plain text content and resets state."""
69
  if file_obj is None:
70
- return "", "No file uploaded.", ""
 
71
 
72
  file_path = file_obj.name
73
  filename = os.path.basename(file_path)
@@ -82,7 +83,7 @@ def process_file(file_obj):
82
  with open(file_path, 'r', encoding='utf-8') as f:
83
  text_content = f.read()
84
  except Exception as e:
85
- return "", f"Error reading file: {e}", ""
86
 
87
  # Reset the coded data state when a new file is loaded
88
  initial_coded_df = get_initial_df()
@@ -110,7 +111,6 @@ def apply_code(
110
 
111
 
112
  # Extract the metadata values from the list
113
- # metadata_values is a list of strings corresponding to the keys in METADATA_FIELDS
114
  meta_dict = dict(zip(METADATA_FIELDS.keys(), metadata_values))
115
 
116
  # Find context: locate the start of the segment in the full text
@@ -182,17 +182,15 @@ with gr.Blocks(title="Qualitative Coding Interface") as demo:
182
  )
183
  status_message = gr.Textbox(label="Status", value="Ready", scale=2)
184
 
185
- # Use gr.Interface briefly just to handle the file upload and state update cleanly
186
- # NOTE: The 'allow_flagging' argument has been removed to fix the TypeError.
187
- gr.Interface(
188
  fn=process_file,
189
  inputs=file_input,
190
- outputs=[full_transcript_text, status_message, current_file_id, coded_data_state],
191
- api_name=False,
192
- live=False,
193
- # Hide the default UI generated by Interface (we handle it below)
194
- ).clear()
195
-
196
  gr.Markdown("---")
197
  gr.Markdown("## 📝 Interview Metadata")
198
 
 
67
  def process_file(file_obj):
68
  """Handles file upload and returns the plain text content and resets state."""
69
  if file_obj is None:
70
+ # Return default values to clear the interface
71
+ return "", "No file uploaded.", "", get_initial_df()
72
 
73
  file_path = file_obj.name
74
  filename = os.path.basename(file_path)
 
83
  with open(file_path, 'r', encoding='utf-8') as f:
84
  text_content = f.read()
85
  except Exception as e:
86
+ return "", f"Error reading file: {e}", "", get_initial_df()
87
 
88
  # Reset the coded data state when a new file is loaded
89
  initial_coded_df = get_initial_df()
 
111
 
112
 
113
  # Extract the metadata values from the list
 
114
  meta_dict = dict(zip(METADATA_FIELDS.keys(), metadata_values))
115
 
116
  # Find context: locate the start of the segment in the full text
 
182
  )
183
  status_message = gr.Textbox(label="Status", value="Ready", scale=2)
184
 
185
+ # *** FIX IMPLEMENTATION ***
186
+ # Replaced gr.Interface with the gr.File.change() method
187
+ file_input.change(
188
  fn=process_file,
189
  inputs=file_input,
190
+ outputs=[full_transcript_text, status_message, current_file_id, coded_data_state]
191
+ )
192
+ # *** END FIX ***
193
+
 
 
194
  gr.Markdown("---")
195
  gr.Markdown("## 📝 Interview Metadata")
196