diff --git a/app.py b/app.py index 475b5c2..bcc397f 100644 --- a/app.py +++ b/app.py @@ -148,7 +148,6 @@ def generate_compare_genAI(extracted_values, values_from_excel, keys_of_interest st.error(f"Invalid JSON returned by AI: {cleaned_response}") return {} - def main(): st.title("Invoice Processing") st.markdown("") @@ -173,7 +172,6 @@ def main(): if st.button(button_label): with st.spinner("Evaluating..."): generated_text = generate_content(image) # Generate content from image - #st.write(f"Generated text: {generated_text}") st.image(uploaded_image, caption="", use_column_width=True) @@ -192,7 +190,6 @@ def main(): try: # Extract and parse the JSON response json_str = generated_text.strip().split('\n', 1)[-1].replace("```json", "").replace("```", "").strip() - #st.write(f"Extracted JSON string: {json_str}") extracted_data = json.loads(json_str) # Use json.loads to parse # Display extracted data in bullet format @@ -203,12 +200,10 @@ def main(): # Extract contract number contract_number = extracted_data.get("Contract Number", "") - #st.write(f"Contract Number extracted: {contract_number}") # Find the row in the Excel DataFrame for the contract number if not df.empty and contract_number: contract_row = df[df['Contract Number'] == contract_number] - #st.write(f"Found contract row: {contract_row}") if not contract_row.empty: keys_of_interest = [ @@ -235,16 +230,12 @@ def main(): else: values_from_excel.append("") # Placeholder if the key is not found - #st.write(f"Extracted values: {extracted_values}") - #st.write(f"Values from Excel: {values_from_excel}") - # Use the AI model to generate comparison results comparison_results = generate_compare_genAI(extracted_values, values_from_excel, keys_of_interest) - #st.write(f"Comparison results: {comparison_results}") # Initialize checkbox states in session_state if not already done if 'checkbox_states' not in st.session_state: - st.session_state.checkbox_states = {key: (comparison_results[key] == "Yes") for key in keys_of_interest} + st.session_state.checkbox_states = {key: (comparison_results.get(key, "No") == "Yes") for key in keys_of_interest} # Add checkboxes directly to the DataFrame editable_df = pd.DataFrame({ @@ -254,7 +245,7 @@ def main(): }) editable_df['Match'] = [ - st.checkbox(f"Match for {key}", value=st.session_state.checkbox_states[key], key=f"checkbox_{key}") + st.checkbox(f"Match for {key}", value=st.session_state.checkbox_states.get(key, False), key=f"checkbox_{key}") for key in keys_of_interest ] @@ -265,9 +256,6 @@ def main(): # Display the DataFrame with checkboxes st.dataframe(editable_df, use_container_width=True) - # Display comparison results as JSON - #st.json(comparison_results) - else: st.warning(f"No data found for contract number: {contract_number}") else: @@ -277,6 +265,7 @@ def main(): st.error(f"Failed to parse generated text as JSON: {e}. Please check the output.") except Exception as e: st.error(f"An error occurred: {e}") + if __name__ == "__main__": if st.session_state.logged_in: