From b208fd0a766d273839392d3a1bf69423797295a5 Mon Sep 17 00:00:00 2001 From: etwk <48991073+etwk@users.noreply.github.com> Date: Sat, 31 Aug 2024 08:59:02 +0000 Subject: [PATCH] update report format --- src/utils.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/utils.py b/src/utils.py index 30909e1..e6842ce 100644 --- a/src/utils.py +++ b/src/utils.py @@ -45,10 +45,12 @@ def generate_report_markdown(input_text, verdicts): # Add verdicts markdown.append("## Fact Check\n") for i, verdict in enumerate(verdicts, start=1): + weights = verdict['weights'] + percentage = calculate_percentage(weights['winning'], weights['valid']) markdown.append(f"### Statement {i}\n") markdown.append(f"**Statement**: {verdict['statement']}\n") - markdown.append(f"**Verdict**: `{verdict['verdict']}`\n") - markdown.append(f"**Weight**: {verdict['weights']['winning']} out of {verdict['weights']['valid']} ({verdict['weights']['irrelevant']} irrelevant)\n") + markdown.append(f"**Verdict**: `{verdict['verdict'].capitalize()}`\n") + markdown.append(f"**Weight**: {percentage} (false: {weights['false']}, true: {weights['true']}, irrelevant: {weights['irrelevant']})\n") markdown.append(f"**Citations**:\n\n{verdict['citation']}\n") markdown_str = "\n".join(markdown) @@ -152,6 +154,14 @@ def get_md5(input): md5_hash = hashlib.md5(input.encode()) return md5_hash.hexdigest() +def calculate_percentage(part, whole): + # Check to avoid division by zero + if whole == 0: + return "N/A" + + percentage = round((part / whole) * 100) + return f"{percentage}%" + # generate str for stream def get_stream(stage: str = 'wait', content = None): message = {"stage": stage, "content": content}