Spaces:
Build error
Build error
File size: 4,455 Bytes
48e7216 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
import streamlit as st
from utils.logger import setup_logger
import pandas as pd
from PIL import Image
import os
logger = setup_logger(__name__)
# def prune_others_for_display(analysis_results_for_id):
# data_to_display = {}
# data_to_display["document_category"] = "income_document"
# data_to_display["document_type"] = "payslip"
# data_to_display["employee_name"] = analysis_results_for_id.get(
# "employee_name", None)
# data_to_display["employer_name"] = analysis_results_for_id.get(
# "employer_name", None)
# data_to_display["payslip_date"] = analysis_results_for_id.get(
# "payslip_date", None)
# data_to_display["pay_period_start"] = analysis_results_for_id.get(
# "pay_period_start", None)
# data_to_display["pay_period_end"] = analysis_results_for_id.get(
# "pay_period_end", None)
# data_to_display["payment_frequency"] = analysis_results_for_id.get(
# "payment_frequency", None)
# data_to_display["basic_pay"] = analysis_results_for_id.get(
# "basic_pay", None)
# data_to_display["net_pay"] = analysis_results_for_id.get(
# "net_pay", None)
# data_to_display["gross_pay"] = analysis_results_for_id.get(
# "gross_pay", None)
# data_to_display["salary_components"] = analysis_results_for_id.get(
# "salary_components", None)
# data_to_display["ni_contribution"] = analysis_results_for_id.get(
# "ni_contribution", None)
# data_to_display["tax_deduction"] = analysis_results_for_id.get(
# "tax_deduction", None)
# data_to_display["other_deductions"] = analysis_results_for_id.get(
# "other_deductions", None)
# return data_to_display
def display_others(extracted_files, analysis_results_pruned):
col1, col2 = st.columns([2, 3])
logger.info(f"file_path while displaying: {extracted_files}")
st.markdown("---")
with col1:
if len(extracted_files) > 1:
st.image(extracted_files, caption=[os.path.basename(
img) for img in extracted_files], use_container_width=True)
else:
image = Image.open(extracted_files[0])
st.image(image, caption=os.path.basename(
extracted_files[0])) # ,
# use_container_width=True)
logger.info(
f"analysis_results_pruned: {analysis_results_pruned}")
with col2:
for key, value in analysis_results_pruned.items():
if isinstance(value, dict):
st.write(f"**{key}:**")
sub_data = {"Key": [], "Value": []}
for sub_key, sub_value in value.items():
sub_data["Key"].append(sub_key)
sub_data["Value"].append(sub_value)
sub_df = pd.DataFrame(sub_data)
sub_df.index += 1
st.dataframe(sub_df, use_container_width=True)
# sub_col1, sub_col2 = st.columns(2)
# for sub_key, sub_value in value.items():
# with sub_col1:
# st.write(f"{sub_key}",
# use_container_width=True)
# with sub_col2:
# with st.container():
# st.write(f"{sub_value}",
# use_container_width=True)
else:
simple_data = {"Key": [key], "Value": [value]}
simple_df = pd.DataFrame(simple_data)
simple_df.index += 1
logger.info(f"simple_df['Value'] : {simple_df['Value']}")
# simple_df["Value"] = simple_df["Value"].apply(lambda x: str(x) if not pd.isnull(x) else "")
def safe_to_str(x):
try:
if pd.isna(x):
return ""
except:
pass
return str(x)
simple_df["Value"] = simple_df["Value"].apply(safe_to_str)
st.dataframe(simple_df, use_container_width=True)
# sub_col1, sub_col2 = st.columns(2)
# with sub_col1:
# st.write(f"{key}", use_container_width=True)
# with st.container():
# with sub_col2:
# st.write(f"{value}", use_container_width=True)
logger.info(f"simple_df: {simple_df}")
|