Skip to content

Commit 5db9ce3

Browse files
committed
Persist status column values
1 parent aa11c03 commit 5db9ce3

File tree

2 files changed

+230
-212
lines changed

2 files changed

+230
-212
lines changed

poligrapher/gradio_app/app.py

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,24 @@ def yml_exists(row):
2424
yml_path = f"./output/{company_name}/graph-original.full.yml"
2525
return os.path.exists(yml_path)
2626

27-
df["YML Exists"] = df.apply(lambda row: yml_exists(row), axis=1)
27+
df["Status"] = df.apply(yml_exists, axis=1)
2828

29-
# For display: show checkmark or red X
30-
def yml_status(val):
31-
return "✅" if val else "⚠️"
32-
33-
df["Status"] = df["YML Exists"].apply(yml_status)
3429
# Move Status to the leftmost column
3530
cols = df.columns.tolist()
3631
if "Status" in cols:
3732
cols.insert(0, cols.pop(cols.index("Status")))
3833
df = df[cols]
34+
# Persist Status values back to the CSV without adding helper columns
35+
try:
36+
if "Company Name" in df.columns and "Status" in df.columns:
37+
orig_df = pd.read_csv(csv_path)
38+
if "Company Name" in orig_df.columns:
39+
status_map = df.set_index("Company Name")["Status"].to_dict()
40+
orig_df["Status"] = orig_df.get("Company Name").map(status_map)
41+
# Write the updated CSV (preserve original column order plus Status if new)
42+
orig_df.to_csv(csv_path, index=False)
43+
except Exception as e:
44+
logger.error("Failed to persist Status to CSV: %s", e)
3945
return df
4046

4147
def get_analysis_results():
@@ -84,7 +90,7 @@ def visualize_graph(output_folder):
8490
if not os.path.exists(yml_file):
8591
return "YML file not found for visualization."
8692
try:
87-
with open(yml_file, "r") as file:
93+
with open(yml_file, "r", encoding="utf-8") as file:
8894
data = yaml.safe_load(file)
8995
G = nx.DiGraph()
9096
for node in data.get("nodes", []):
@@ -200,8 +206,9 @@ def on_submit_click(company_name, privacy_policy_url, kind):
200206
gr.Markdown("#### Company Privacy Policy List")
201207
company_df_data = get_company_df()
202208
# Count successes and errors from Status column
203-
num_success = (company_df_data["Status"] == "✅").sum()
204-
num_error = (company_df_data["Status"] != "✅").sum()
209+
# Ensure boolean counts (Status is maintained as bool and persisted to CSV as bool)
210+
num_success = int(company_df_data["Status"].astype(bool).sum())
211+
num_error = int(len(company_df_data) - num_success)
205212
gr.Markdown(
206213
f"**Status Summary:** {num_success} successful, {num_error} with incomplete YML generation."
207214
)
@@ -210,17 +217,28 @@ def on_submit_click(company_name, privacy_policy_url, kind):
210217
# Show only relevant columns, including Status
211218
display_cols = [col for col in company_df_data.columns if col not in ["YML Exists"]]
212219

220+
# Prepare a display copy where Status is shown as an emoji, but keep the underlying CSV boolean-only
221+
def _status_to_emoji(v):
222+
try:
223+
return "✅" if bool(v) else "⚠️"
224+
except Exception:
225+
return "⚠️"
226+
227+
display_df = company_df_data.copy()
228+
if "Status" in display_df.columns:
229+
display_df["Status"] = display_df["Status"].apply(_status_to_emoji)
230+
213231
with gr.Row():
214232
company_df = gr.Dataframe(
215-
value=company_df_data[display_cols], label="Companies", interactive=False
233+
value=display_df[display_cols], label="Companies", interactive=False
216234
)
217235
with gr.Row():
218236
company_info = gr.Markdown("", visible=True)
219237
with gr.Row():
220238
png_image = gr.Image(label="Knowledge Graph", visible=True)
221239
scoring_output = gr.Textbox(label="Scoring Results", interactive=False)
222240

223-
def on_company_select(df: pd.DataFrame, selection: gr.SelectData):
241+
def on_company_select(_df: pd.DataFrame, selection: gr.SelectData):
224242
if selection is None:
225243
return "", None
226244
row_value = selection.row_value

0 commit comments

Comments
 (0)