Spaces:
Build error
Build error
| 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}") | |