Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -23,14 +23,6 @@ METADATA_FIELDS = {
|
|
| 23 |
"age": "Age",
|
| 24 |
}
|
| 25 |
|
| 26 |
-
COLOR_MAP = {
|
| 27 |
-
"Communication Barrier": "lightblue",
|
| 28 |
-
"Emotional Support": "lightgreen",
|
| 29 |
-
"Future Aspirations": "khaki",
|
| 30 |
-
"Financial Stress": "lightpink",
|
| 31 |
-
"Follow-up Needed": "orange",
|
| 32 |
-
}
|
| 33 |
-
|
| 34 |
# --- File processing ---
|
| 35 |
def read_docx(path):
|
| 36 |
if not docx:
|
|
@@ -70,15 +62,18 @@ def process_file(file_obj):
|
|
| 70 |
# --- Apply coding ---
|
| 71 |
def apply_code(df, segment, code, file_id, *metadata_values):
|
| 72 |
if not file_id:
|
| 73 |
-
return df, "⚠️ Upload a file first"
|
| 74 |
if not segment:
|
| 75 |
-
return df, "⚠️ Paste a segment first"
|
| 76 |
if not code:
|
| 77 |
-
return df, "⚠️ Select a code"
|
|
|
|
| 78 |
meta_dict = dict(zip(METADATA_FIELDS.keys(), metadata_values))
|
| 79 |
new_row = {"File ID": file_id, "Coded Segment": segment, "Code": code, **meta_dict}
|
| 80 |
df = pd.concat([df, pd.DataFrame([new_row])], ignore_index=True)
|
| 81 |
-
|
|
|
|
|
|
|
| 82 |
|
| 83 |
# --- Add new code ---
|
| 84 |
def add_new_code(new_code, code_list):
|
|
@@ -165,7 +160,7 @@ with gr.Blocks() as demo:
|
|
| 165 |
apply_btn.click(
|
| 166 |
apply_code,
|
| 167 |
inputs=[coded_df_state, segment_box, code_dropdown, file_id] + metadata_inputs,
|
| 168 |
-
outputs=[coded_df_state, status]
|
| 169 |
)
|
| 170 |
|
| 171 |
coded_df_state.change(lambda df: df, inputs=coded_df_state, outputs=table)
|
|
|
|
| 23 |
"age": "Age",
|
| 24 |
}
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
# --- File processing ---
|
| 27 |
def read_docx(path):
|
| 28 |
if not docx:
|
|
|
|
| 62 |
# --- Apply coding ---
|
| 63 |
def apply_code(df, segment, code, file_id, *metadata_values):
|
| 64 |
if not file_id:
|
| 65 |
+
return df, "⚠️ Upload a file first", gr.update(value="")
|
| 66 |
if not segment:
|
| 67 |
+
return df, "⚠️ Paste a segment first", gr.update(value="")
|
| 68 |
if not code:
|
| 69 |
+
return df, "⚠️ Select a code", gr.update(value="")
|
| 70 |
+
|
| 71 |
meta_dict = dict(zip(METADATA_FIELDS.keys(), metadata_values))
|
| 72 |
new_row = {"File ID": file_id, "Coded Segment": segment, "Code": code, **meta_dict}
|
| 73 |
df = pd.concat([df, pd.DataFrame([new_row])], ignore_index=True)
|
| 74 |
+
|
| 75 |
+
# Clear segment box after applying
|
| 76 |
+
return df, f"✅ Segment coded as '{code}'", gr.update(value="")
|
| 77 |
|
| 78 |
# --- Add new code ---
|
| 79 |
def add_new_code(new_code, code_list):
|
|
|
|
| 160 |
apply_btn.click(
|
| 161 |
apply_code,
|
| 162 |
inputs=[coded_df_state, segment_box, code_dropdown, file_id] + metadata_inputs,
|
| 163 |
+
outputs=[coded_df_state, status, segment_box]
|
| 164 |
)
|
| 165 |
|
| 166 |
coded_df_state.change(lambda df: df, inputs=coded_df_state, outputs=table)
|