Spaces:
				
			
			
	
			
			
		Sleeping
		
	
	
	
			
			
	
	
	
	
		
		
		Sleeping
		
	Update app.py
Browse files
    	
        app.py
    CHANGED
    
    | 
         @@ -1 +1,569 @@ 
     | 
|
| 1 | 
         
            -
            import  
     | 
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
| 
         | 
|
| 1 | 
         
            +
            import streamlit as st
         
     | 
| 2 | 
         
            +
            import pandas as pd
         
     | 
| 3 | 
         
            +
            import numpy as np
         
     | 
| 4 | 
         
            +
            from streamlit_option_menu import option_menu
         
     | 
| 5 | 
         
            +
            from llm import OpenaiAPI
         
     | 
| 6 | 
         
            +
            from pdfProcessor import PDFProcessor
         
     | 
| 7 | 
         
            +
            from embeddingsProcessor import EmbeddingsProcessor
         
     | 
| 8 | 
         
            +
            from similarityCalculator import SimilarityCalculator
         
     | 
| 9 | 
         
            +
            from findUpdate import FindUpdate
         
     | 
| 10 | 
         
            +
            from pdfDocumentProcessor import PDFDocumentProcessor
         
     | 
| 11 | 
         
            +
            from streamlit_modal import Modal
         
     | 
| 12 | 
         
            +
            import os
         
     | 
| 13 | 
         
            +
            import time
         
     | 
| 14 | 
         
            +
            import shutil
         
     | 
| 15 | 
         
            +
            import base64
         
     | 
| 16 | 
         
            +
            from findUpdate import FindUpdate  # Import the FindUpdate class
         
     | 
| 17 | 
         
            +
            from tempfile import NamedTemporaryFile
         
     | 
| 18 | 
         
            +
             
     | 
| 19 | 
         
            +
             
     | 
| 20 | 
         
            +
            icon_url = "https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Ftheindustryspread.com%2Fwp-content%2Fuploads%2F2019%2F05%2FBroadridge-1.png"
         
     | 
| 21 | 
         
            +
            st.set_page_config(page_title="Contract AI", page_icon='https://www.adople.com/assets/img/logo/title2.png',initial_sidebar_state="collapsed")
         
     | 
| 22 | 
         
            +
             
     | 
| 23 | 
         
            +
             
     | 
| 24 | 
         
            +
            openai = OpenaiAPI()
         
     | 
| 25 | 
         
            +
             
     | 
| 26 | 
         
            +
            # CSS to make the option menu sticky and to target specific container class
         
     | 
| 27 | 
         
            +
            st.markdown(
         
     | 
| 28 | 
         
            +
                """
         
     | 
| 29 | 
         
            +
                <style>
         
     | 
| 30 | 
         
            +
                @import url('https://fonts.googleapis.com/css2?family=Quicksand:wght@300..700&display=swap');
         
     | 
| 31 | 
         
            +
                body {
         
     | 
| 32 | 
         
            +
                    font-family: 'Quicksand', sans-serif;
         
     | 
| 33 | 
         
            +
                }
         
     | 
| 34 | 
         
            +
                .st-emotion-cache-13ln4jf.ea3mdgi5 {
         
     | 
| 35 | 
         
            +
                    position: -webkit-sticky;
         
     | 
| 36 | 
         
            +
                    position: sticky;
         
     | 
| 37 | 
         
            +
                    top: 10;
         
     | 
| 38 | 
         
            +
                    z-index: 100;
         
     | 
| 39 | 
         
            +
                    padding-top: 42px;
         
     | 
| 40 | 
         
            +
                    padding-bottom: 10px;
         
     | 
| 41 | 
         
            +
                    border-bottom: 1px solid #e6e6e6;
         
     | 
| 42 | 
         
            +
                }
         
     | 
| 43 | 
         
            +
                header.st-emotion-cache-12fmjuu.ezrtsby2 {
         
     | 
| 44 | 
         
            +
                  background-color: #f0f2f6 !important;
         
     | 
| 45 | 
         
            +
                }
         
     | 
| 46 | 
         
            +
                .st-emotion-cache-12fmjuu.ezrtsby2{
         
     | 
| 47 | 
         
            +
                    background:url('https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Ftheindustryspread.com%2Fwp-content%2Fuploads%2F2019%2F05%2FBroadridge-1.png') no-repeat;
         
     | 
| 48 | 
         
            +
                    background-size: 250px 50px;
         
     | 
| 49 | 
         
            +
                    background-position: center;
         
     | 
| 50 | 
         
            +
                    padding-left: 50px;
         
     | 
| 51 | 
         
            +
                  }
         
     | 
| 52 | 
         
            +
                .st-emotion-cache-1vt4y43.ef3psqc13{
         
     | 
| 53 | 
         
            +
             
     | 
| 54 | 
         
            +
                }
         
     | 
| 55 | 
         
            +
                </style>
         
     | 
| 56 | 
         
            +
                """,
         
     | 
| 57 | 
         
            +
                unsafe_allow_html=True,
         
     | 
| 58 | 
         
            +
            )
         
     | 
| 59 | 
         
            +
             
     | 
| 60 | 
         
            +
            # Create the sticky top horizontal option menu within the specified container
         
     | 
| 61 | 
         
            +
            with st.container():
         
     | 
| 62 | 
         
            +
                selected_main_option = option_menu(
         
     | 
| 63 | 
         
            +
                    menu_title=None,
         
     | 
| 64 | 
         
            +
                    options=["Dashboard", "Update Find", "Comparizer"],
         
     | 
| 65 | 
         
            +
                    icons=['list', 'binoculars-fill', 'patch-check-fill'],
         
     | 
| 66 | 
         
            +
                    menu_icon="cast",
         
     | 
| 67 | 
         
            +
                    default_index=0,
         
     | 
| 68 | 
         
            +
                    orientation="horizontal",
         
     | 
| 69 | 
         
            +
                )
         
     | 
| 70 | 
         
            +
                st.markdown('</div>', unsafe_allow_html=True)
         
     | 
| 71 | 
         
            +
            uploaded_file=''
         
     | 
| 72 | 
         
            +
            # Display different content based on the menu selection
         
     | 
| 73 | 
         
            +
            if selected_main_option == "Dashboard":
         
     | 
| 74 | 
         
            +
                st.markdown("""
         
     | 
| 75 | 
         
            +
                  <style>
         
     | 
| 76 | 
         
            +
                  @import url('https://fonts.googleapis.com/css2?family=Quicksand:wght@300..700&display=swap');
         
     | 
| 77 | 
         
            +
                  body {
         
     | 
| 78 | 
         
            +
                      font-family: "Quicksand", sans-serif;
         
     | 
| 79 | 
         
            +
                      font-optical-sizing: auto;
         
     | 
| 80 | 
         
            +
                      font-weight: <weight>;
         
     | 
| 81 | 
         
            +
                      font-style: normal;
         
     | 
| 82 | 
         
            +
                  }
         
     | 
| 83 | 
         
            +
                  .topic-box {
         
     | 
| 84 | 
         
            +
                      background-color: #f0f0f0;
         
     | 
| 85 | 
         
            +
                      padding: 10px;
         
     | 
| 86 | 
         
            +
                      border-radius: 5px;
         
     | 
| 87 | 
         
            +
                      margin-bottom: 10px;
         
     | 
| 88 | 
         
            +
                  }
         
     | 
| 89 | 
         
            +
                  .topic-box:hover{
         
     | 
| 90 | 
         
            +
                    background-color: #000080;
         
     | 
| 91 | 
         
            +
                    box-shadow: 6px 1px 12px gray;
         
     | 
| 92 | 
         
            +
                    color:#fff;
         
     | 
| 93 | 
         
            +
                  }
         
     | 
| 94 | 
         
            +
                  .topic-title {
         
     | 
| 95 | 
         
            +
                      font-weight: bold;
         
     | 
| 96 | 
         
            +
                  }
         
     | 
| 97 | 
         
            +
                  .st-emotion-cache-ocqkz7 {
         
     | 
| 98 | 
         
            +
                    gap: 1.5rem;
         
     | 
| 99 | 
         
            +
                    }
         
     | 
| 100 | 
         
            +
                  .st-emotion-cache-1vt4y43.ef3psqc13{
         
     | 
| 101 | 
         
            +
                    background-color: #f0f2f6 !important;
         
     | 
| 102 | 
         
            +
                    padding: 10px;
         
     | 
| 103 | 
         
            +
                    color:black;
         
     | 
| 104 | 
         
            +
                    font-weight: bold;
         
     | 
| 105 | 
         
            +
                    width: 200px;
         
     | 
| 106 | 
         
            +
                    border-style: none;
         
     | 
| 107 | 
         
            +
                    border-radius: 15px;
         
     | 
| 108 | 
         
            +
                    margin-bottom: 10px;
         
     | 
| 109 | 
         
            +
                  }
         
     | 
| 110 | 
         
            +
                  .st-emotion-cache-1vt4y43.ef3psqc13:hover{
         
     | 
| 111 | 
         
            +
                    background-color: #00578E !important;
         
     | 
| 112 | 
         
            +
                    box-shadow: 6px 1px 12px gray;
         
     | 
| 113 | 
         
            +
                    color:white;
         
     | 
| 114 | 
         
            +
                    font-weight: bold;
         
     | 
| 115 | 
         
            +
                    border-style: none;
         
     | 
| 116 | 
         
            +
                    width: 200px;
         
     | 
| 117 | 
         
            +
                  }
         
     | 
| 118 | 
         
            +
                  </style>
         
     | 
| 119 | 
         
            +
                  """, unsafe_allow_html=True)
         
     | 
| 120 | 
         
            +
                button_value=''
         
     | 
| 121 | 
         
            +
                with st.sidebar:
         
     | 
| 122 | 
         
            +
                    button_value = option_menu(
         
     | 
| 123 | 
         
            +
                        "CONTRACT AI",
         
     | 
| 124 | 
         
            +
                        [
         
     | 
| 125 | 
         
            +
                            'Home', 'Tags', 'Clauses', 'Summarizer', 'Headings', 'Extract Date',
         
     | 
| 126 | 
         
            +
                            'Pdf to Json', 'Key Values', 'Incorrect Sentences',
         
     | 
| 127 | 
         
            +
                            'Incomplete Sentences', 'Aggressive Content', "Contract Generator"
         
     | 
| 128 | 
         
            +
                        ],
         
     | 
| 129 | 
         
            +
                        icons=[
         
     | 
| 130 | 
         
            +
                            'arrow-right-circle-fill'] * 12,  # repeated icon list
         
     | 
| 131 | 
         
            +
                        menu_icon="house-gear-fill",
         
     | 
| 132 | 
         
            +
                        default_index=0
         
     | 
| 133 | 
         
            +
                    )
         
     | 
| 134 | 
         
            +
                    uploaded_file=st.file_uploader("Upload Document")
         
     | 
| 135 | 
         
            +
             
     | 
| 136 | 
         
            +
                uploaded_file=st.file_uploader("Upload your Document")
         
     | 
| 137 | 
         
            +
                col1, col2, col3 = st.columns(3)
         
     | 
| 138 | 
         
            +
                with col1:
         
     | 
| 139 | 
         
            +
                    if st.button("Tags"):
         
     | 
| 140 | 
         
            +
                        button_value = 'Tags'
         
     | 
| 141 | 
         
            +
                with col2:
         
     | 
| 142 | 
         
            +
                    if st.button("Clauses"):
         
     | 
| 143 | 
         
            +
                        button_value = 'Clauses'
         
     | 
| 144 | 
         
            +
                with col3:
         
     | 
| 145 | 
         
            +
                    if st.button("Summarizer"):
         
     | 
| 146 | 
         
            +
                        button_value = 'Summarizer'
         
     | 
| 147 | 
         
            +
             
     | 
| 148 | 
         
            +
                col4, col5, col6= st.columns(3)
         
     | 
| 149 | 
         
            +
                with col4:
         
     | 
| 150 | 
         
            +
                    if st.button("Headings"):
         
     | 
| 151 | 
         
            +
                        button_value = 'Headings'
         
     | 
| 152 | 
         
            +
                with col5:
         
     | 
| 153 | 
         
            +
                    if st.button("Extract Date"):
         
     | 
| 154 | 
         
            +
                        button_value = 'Extract Date'
         
     | 
| 155 | 
         
            +
                with col6:
         
     | 
| 156 | 
         
            +
                    if st.button("Pdf to Json"):
         
     | 
| 157 | 
         
            +
                        button_value = 'Pdf to Json'
         
     | 
| 158 | 
         
            +
             
     | 
| 159 | 
         
            +
                col7, col8, col9= st.columns(3)
         
     | 
| 160 | 
         
            +
                with col7:
         
     | 
| 161 | 
         
            +
                    if st.button("Key Values"):button_value = 'Key Values'
         
     | 
| 162 | 
         
            +
                with col8:
         
     | 
| 163 | 
         
            +
                    if st.button("Incorrect Sentences"):button_value = 'Incorrect Sentences'
         
     | 
| 164 | 
         
            +
                with col9:
         
     | 
| 165 | 
         
            +
                    if st.button("Incomplete Sentences"):button_value = 'Incomplete Sentences'
         
     | 
| 166 | 
         
            +
             
     | 
| 167 | 
         
            +
                col10, col11,_= st.columns(3)
         
     | 
| 168 | 
         
            +
                with col10:
         
     | 
| 169 | 
         
            +
                    if st.button("Aggressive Content"):
         
     | 
| 170 | 
         
            +
                        button_value = 'Aggressive Content'
         
     | 
| 171 | 
         
            +
                with col11:
         
     | 
| 172 | 
         
            +
                    if st.button("Contract Generator"):
         
     | 
| 173 | 
         
            +
                        button_value = 'Contract Generator'
         
     | 
| 174 | 
         
            +
             
     | 
| 175 | 
         
            +
                if button_value == '' or button_value == 'Home':
         
     | 
| 176 | 
         
            +
                    st.title('')
         
     | 
| 177 | 
         
            +
                # Tags
         
     | 
| 178 | 
         
            +
                elif button_value == 'Tags':
         
     | 
| 179 | 
         
            +
                    confirmationTag = Modal("Tags Extracter", key= "tag_extract")
         
     | 
| 180 | 
         
            +
                    if uploaded_file is not None:
         
     | 
| 181 | 
         
            +
                      print('File Name : ',uploaded_file.name)
         
     | 
| 182 | 
         
            +
                      ftype=uploaded_file.name.split('.')
         
     | 
| 183 | 
         
            +
                      if ftype[-1]=='pdf':
         
     | 
| 184 | 
         
            +
                          docs_data = openai.pdf_to_text_pypdf2(uploaded_file)
         
     | 
| 185 | 
         
            +
                      elif ftype[-1]=='docx':
         
     | 
| 186 | 
         
            +
                          docs_data = openai.docx_to_text(uploaded_file)
         
     | 
| 187 | 
         
            +
                      conversation = [{"role": "system", "content": """
         
     | 
| 188 | 
         
            +
                                    You are a helpful Tags Extracter.
         
     | 
| 189 | 
         
            +
                                    analyze the given contract to extract tags for following contract in triple backticks.
         
     | 
| 190 | 
         
            +
                                    tags should be bullet points.contract :
         
     | 
| 191 | 
         
            +
                                    """},
         
     | 
| 192 | 
         
            +
                                    {"role": "user", "content": f"```contract: {docs_data}```"}]
         
     | 
| 193 | 
         
            +
                      get_response = openai.get_response(conversation)
         
     | 
| 194 | 
         
            +
             
     | 
| 195 | 
         
            +
                      if get_response == ['', None]:
         
     | 
| 196 | 
         
            +
                        st.toast("No Result is founded.")
         
     | 
| 197 | 
         
            +
                      else:
         
     | 
| 198 | 
         
            +
                        with confirmationTag.container():
         
     | 
| 199 | 
         
            +
                          st.write("Similarity Scores Table:")
         
     | 
| 200 | 
         
            +
                          st.write(get_response)
         
     | 
| 201 | 
         
            +
                          if st.button('Close Window'):
         
     | 
| 202 | 
         
            +
                              confirmationTag.close()
         
     | 
| 203 | 
         
            +
                    else:
         
     | 
| 204 | 
         
            +
                        st.toast("No Document is Uploaded.")
         
     | 
| 205 | 
         
            +
             
     | 
| 206 | 
         
            +
                # Clauses
         
     | 
| 207 | 
         
            +
                elif button_value == 'Clauses':
         
     | 
| 208 | 
         
            +
                    confirmationClauses = Modal("Clauses Extracter", key= "clauses_extract")
         
     | 
| 209 | 
         
            +
                    if uploaded_file is not None:
         
     | 
| 210 | 
         
            +
                      print('File Name : ',uploaded_file.name)
         
     | 
| 211 | 
         
            +
                      ftype=uploaded_file.name.split('.')
         
     | 
| 212 | 
         
            +
                      if ftype[-1]=='pdf':
         
     | 
| 213 | 
         
            +
                        docs_data = openai.pdf_to_text_pypdf2(uploaded_file)
         
     | 
| 214 | 
         
            +
                      elif ftype[-1]=='docx':
         
     | 
| 215 | 
         
            +
                        docs_data = openai.docx_to_text(uploaded_file)
         
     | 
| 216 | 
         
            +
                      conversation = [{"role": "system", "content": """
         
     | 
| 217 | 
         
            +
                                    You are a helpful Cluases and SubCluases Extracter From Given Content
         
     | 
| 218 | 
         
            +
                                    Extract clauses and sub-clauses from the provided contract PDF
         
     | 
| 219 | 
         
            +
                                    """},
         
     | 
| 220 | 
         
            +
                                    {"role": "user", "content": f"```contract: {docs_data}```"}]
         
     | 
| 221 | 
         
            +
                      get_response = openai.get_response(conversation)
         
     | 
| 222 | 
         
            +
                      if get_response == ['', None]:
         
     | 
| 223 | 
         
            +
                          st.write("No Result is founded.")
         
     | 
| 224 | 
         
            +
                      else:
         
     | 
| 225 | 
         
            +
                          with confirmationClauses.container():
         
     | 
| 226 | 
         
            +
                              st.write("Similarity Scores Table:")
         
     | 
| 227 | 
         
            +
                              st.write(get_response)
         
     | 
| 228 | 
         
            +
             
     | 
| 229 | 
         
            +
                              if st.button('Close.'):
         
     | 
| 230 | 
         
            +
                                  confirmationClauses.close()
         
     | 
| 231 | 
         
            +
                    else:
         
     | 
| 232 | 
         
            +
                        st.toast("No Document is Uploaded.")
         
     | 
| 233 | 
         
            +
             
     | 
| 234 | 
         
            +
                # Summarizer
         
     | 
| 235 | 
         
            +
                elif button_value == 'Summarizer':
         
     | 
| 236 | 
         
            +
                    confirmationSummarizer = Modal("summarizer Extracter", key= "summarizer_extract")
         
     | 
| 237 | 
         
            +
                    if uploaded_file is not None:
         
     | 
| 238 | 
         
            +
                        print('File Name : ', uploaded_file.name)
         
     | 
| 239 | 
         
            +
                        ftype = uploaded_file.name.split('.')
         
     | 
| 240 | 
         
            +
                        if ftype[-1] == 'pdf':
         
     | 
| 241 | 
         
            +
                            docs_data = openai.pdf_to_text_pypdf2(uploaded_file)
         
     | 
| 242 | 
         
            +
                        elif ftype[-1] == 'docx':
         
     | 
| 243 | 
         
            +
                            docs_data = openai.docx_to_text(uploaded_file)
         
     | 
| 244 | 
         
            +
                        conversation = [{"role": "system", "content": """
         
     | 
| 245 | 
         
            +
                                        You are a helpful summarizer.
         
     | 
| 246 | 
         
            +
                                        Write a concise summary of the following contract:
         
     | 
| 247 | 
         
            +
                                        """},
         
     | 
| 248 | 
         
            +
                                        {"role": "user", "content": f"```contract: {docs_data}```"}]
         
     | 
| 249 | 
         
            +
                        get_response = openai.get_response(conversation)
         
     | 
| 250 | 
         
            +
                        if get_response == ['', None]:
         
     | 
| 251 | 
         
            +
                            st.write("No Result is founded.")
         
     | 
| 252 | 
         
            +
                        else:
         
     | 
| 253 | 
         
            +
                            with confirmationSummarizer.container():
         
     | 
| 254 | 
         
            +
                                st.write("summarizer Extracter:")
         
     | 
| 255 | 
         
            +
                                st.write(get_response)
         
     | 
| 256 | 
         
            +
             
     | 
| 257 | 
         
            +
                                if st.button('Close.'):
         
     | 
| 258 | 
         
            +
                                    confirmationSummarizer.close()
         
     | 
| 259 | 
         
            +
                    else:
         
     | 
| 260 | 
         
            +
                        st.toast("No Document is Uploaded.")
         
     | 
| 261 | 
         
            +
             
     | 
| 262 | 
         
            +
                # Headings
         
     | 
| 263 | 
         
            +
                elif button_value == 'Headings':
         
     | 
| 264 | 
         
            +
                    confirmationHeadings = Modal("Headings Extracter", key= "Headings_extract")
         
     | 
| 265 | 
         
            +
                    if uploaded_file is not None:
         
     | 
| 266 | 
         
            +
                      print('File Name : ',uploaded_file.name)
         
     | 
| 267 | 
         
            +
                      ftype=uploaded_file.name.split('.')
         
     | 
| 268 | 
         
            +
                      if ftype[-1]=='pdf':
         
     | 
| 269 | 
         
            +
                        docs_data = openai.pdf_to_text_pypdf2(uploaded_file)
         
     | 
| 270 | 
         
            +
                      elif ftype[-1]=='docx':
         
     | 
| 271 | 
         
            +
                        docs_data = openai.docx_to_text(uploaded_file)
         
     | 
| 272 | 
         
            +
                      conversation = [{"role": "system", "content": """
         
     | 
| 273 | 
         
            +
                                    You are a helpful document assistant.
         
     | 
| 274 | 
         
            +
                                    Extract Headings from given paragraph do not generate just extract the headings from paragraph.
         
     | 
| 275 | 
         
            +
                                    """},
         
     | 
| 276 | 
         
            +
                                    {"role": "user", "content": f"```contract: {docs_data}```"}]
         
     | 
| 277 | 
         
            +
                      get_response = openai.get_response(conversation)
         
     | 
| 278 | 
         
            +
                      if get_response == ['', None]:
         
     | 
| 279 | 
         
            +
                            st.write("No Result is founded.")
         
     | 
| 280 | 
         
            +
                      else:
         
     | 
| 281 | 
         
            +
                          with confirmationHeadings.container():
         
     | 
| 282 | 
         
            +
                              st.write("Headings Extracter:")
         
     | 
| 283 | 
         
            +
                              st.write(get_response)
         
     | 
| 284 | 
         
            +
             
     | 
| 285 | 
         
            +
                              if st.button('Close.'):
         
     | 
| 286 | 
         
            +
                                  confirmationHeadings.close()
         
     | 
| 287 | 
         
            +
                    else:
         
     | 
| 288 | 
         
            +
                        st.toast("No Document is Uploaded.")
         
     | 
| 289 | 
         
            +
             
     | 
| 290 | 
         
            +
                # Extract Date
         
     | 
| 291 | 
         
            +
                elif button_value == 'Extract Date':
         
     | 
| 292 | 
         
            +
                    confirmationExtractDate = Modal("Extract Date Extracter", key= "date_extract")
         
     | 
| 293 | 
         
            +
                    if uploaded_file is not None:
         
     | 
| 294 | 
         
            +
                      print('File Name : ',uploaded_file.name)
         
     | 
| 295 | 
         
            +
                      ftype=uploaded_file.name.split('.')
         
     | 
| 296 | 
         
            +
                      if ftype[-1]=='pdf':
         
     | 
| 297 | 
         
            +
                        docs_data = openai.pdf_to_text_pypdf2(uploaded_file)
         
     | 
| 298 | 
         
            +
                      elif ftype[-1]=='docx':
         
     | 
| 299 | 
         
            +
                        docs_data = openai.docx_to_text(uploaded_file)
         
     | 
| 300 | 
         
            +
                      conversation = [{"role": "system", "content": """
         
     | 
| 301 | 
         
            +
                                    You are a helpful assistant.
         
     | 
| 302 | 
         
            +
                                    Your task is Identify Dates and Durations Mentioned in the contract and extract that date and duration in key-value pair.
         
     | 
| 303 | 
         
            +
                                    format:
         
     | 
| 304 | 
         
            +
                                    date:
         
     | 
| 305 | 
         
            +
                                    -extracted date
         
     | 
| 306 | 
         
            +
                                    -
         
     | 
| 307 | 
         
            +
                                    Durations:
         
     | 
| 308 | 
         
            +
                                    -extracted Durations
         
     | 
| 309 | 
         
            +
                                    -
         
     | 
| 310 | 
         
            +
                                    - """},
         
     | 
| 311 | 
         
            +
                                    {"role": "user", "content": f"```contract: {docs_data}```"}]
         
     | 
| 312 | 
         
            +
                      get_response = openai.get_response(conversation)
         
     | 
| 313 | 
         
            +
                      if get_response == ['', None]:
         
     | 
| 314 | 
         
            +
                          st.write("No Result is founded.")
         
     | 
| 315 | 
         
            +
                      else:
         
     | 
| 316 | 
         
            +
                          with confirmationExtractDate.container():
         
     | 
| 317 | 
         
            +
                              st.write("Extract Date Extracter:")
         
     | 
| 318 | 
         
            +
                              st.write(get_response)
         
     | 
| 319 | 
         
            +
             
     | 
| 320 | 
         
            +
                              if st.button('Close.'):
         
     | 
| 321 | 
         
            +
                                  confirmationExtractDate.close()
         
     | 
| 322 | 
         
            +
                    else:
         
     | 
| 323 | 
         
            +
                        st.toast("No Document is Uploaded.")
         
     | 
| 324 | 
         
            +
             
     | 
| 325 | 
         
            +
                # Pdf to Json
         
     | 
| 326 | 
         
            +
                elif button_value == 'Pdf to Json':
         
     | 
| 327 | 
         
            +
                    confirmationPdf = Modal("Pdf to Json Extracter", key= "Pdf to Json_extract")
         
     | 
| 328 | 
         
            +
                    if uploaded_file is not None:
         
     | 
| 329 | 
         
            +
                      print('File Name : ',uploaded_file.name)
         
     | 
| 330 | 
         
            +
                      ftype=uploaded_file.name.split('.')
         
     | 
| 331 | 
         
            +
                      if ftype[-1]=='pdf':
         
     | 
| 332 | 
         
            +
                        docs_data = openai.pdf_to_text_pypdf2(uploaded_file)
         
     | 
| 333 | 
         
            +
                      elif ftype[-1]=='docx':
         
     | 
| 334 | 
         
            +
                        docs_data = openai.docx_to_text(uploaded_file)
         
     | 
| 335 | 
         
            +
                      conversation = [{"role": "system", "content": """
         
     | 
| 336 | 
         
            +
                                    You are a helpful assistant.
         
     | 
| 337 | 
         
            +
                                    Your task is Get the text and analyse and split it into Topics and Content in json format.Give Proper Name to Topic dont give any Numbers and Dont Give any empty Contents.The Output Format Should Be very good."""},
         
     | 
| 338 | 
         
            +
                                    {"role": "user", "content": f"```contract: {docs_data}```"}]
         
     | 
| 339 | 
         
            +
                      get_response = openai.get_response(conversation)
         
     | 
| 340 | 
         
            +
                      if get_response == ['', None]:
         
     | 
| 341 | 
         
            +
                          st.write("No Result is founded.")
         
     | 
| 342 | 
         
            +
                      else:
         
     | 
| 343 | 
         
            +
                          with confirmationPdf.container():
         
     | 
| 344 | 
         
            +
                              st.write("Pdf to Json Extracter:")
         
     | 
| 345 | 
         
            +
                              st.write(get_response)
         
     | 
| 346 | 
         
            +
             
     | 
| 347 | 
         
            +
                              if st.button('Close.'):
         
     | 
| 348 | 
         
            +
                                  confirmationPdf.close()
         
     | 
| 349 | 
         
            +
                    else:
         
     | 
| 350 | 
         
            +
                        st.toast("No Document is Uploaded.")
         
     | 
| 351 | 
         
            +
             
     | 
| 352 | 
         
            +
                # Key Values
         
     | 
| 353 | 
         
            +
                elif button_value == 'Key Values':
         
     | 
| 354 | 
         
            +
                    confirmationKey= Modal("Key values Extracter", key= "key_values_extract")
         
     | 
| 355 | 
         
            +
                    if uploaded_file is not None:
         
     | 
| 356 | 
         
            +
                      print('File Name : ',uploaded_file.name)
         
     | 
| 357 | 
         
            +
                      ftype=uploaded_file.name.split('.')
         
     | 
| 358 | 
         
            +
                      if ftype[-1]=='pdf':
         
     | 
| 359 | 
         
            +
                        docs_data = openai.pdf_to_text_pypdf2(uploaded_file)
         
     | 
| 360 | 
         
            +
                      elif ftype[-1]=='docx':
         
     | 
| 361 | 
         
            +
                        docs_data = openai.docx_to_text(uploaded_file)
         
     | 
| 362 | 
         
            +
                      conversation = [{"role": "system", "content": """
         
     | 
| 363 | 
         
            +
                                    You are a helpful Keywords Extracter..
         
     | 
| 364 | 
         
            +
                                    analyze the given contract and Extract Keywords for following contract in triple backticks. tags should be bullet points.contract :
         
     | 
| 365 | 
         
            +
                                    """},
         
     | 
| 366 | 
         
            +
                                    {"role": "user", "content": f"```contract: {docs_data}```"}]
         
     | 
| 367 | 
         
            +
                      get_response = openai.get_response(conversation)
         
     | 
| 368 | 
         
            +
                      if get_response == ['', None]:
         
     | 
| 369 | 
         
            +
                          st.write("No Result is founded.")
         
     | 
| 370 | 
         
            +
                      else:
         
     | 
| 371 | 
         
            +
                          with confirmationKey.container():
         
     | 
| 372 | 
         
            +
                              st.write("Key values Extracter:")
         
     | 
| 373 | 
         
            +
                              st.write(get_response)
         
     | 
| 374 | 
         
            +
             
     | 
| 375 | 
         
            +
                              if st.button('Close.'):
         
     | 
| 376 | 
         
            +
                                  confirmationKey.close()
         
     | 
| 377 | 
         
            +
                    else:
         
     | 
| 378 | 
         
            +
                        st.toast("No Document is Uploaded.")
         
     | 
| 379 | 
         
            +
             
     | 
| 380 | 
         
            +
                # Incorrect Sentences
         
     | 
| 381 | 
         
            +
                elif button_value == 'Incorrect Sentences':
         
     | 
| 382 | 
         
            +
                    confirmationIncorrect = Modal("Incorrect Sentences Extracter", key= "Incorrect_Sentences_extract")
         
     | 
| 383 | 
         
            +
                    if uploaded_file is not None:
         
     | 
| 384 | 
         
            +
                      print('File Name : ',uploaded_file.name)
         
     | 
| 385 | 
         
            +
                      ftype=uploaded_file.name.split('.')
         
     | 
| 386 | 
         
            +
                      if ftype[-1]=='pdf':
         
     | 
| 387 | 
         
            +
                        docs_data = openai.pdf_to_text_pypdf2(uploaded_file)
         
     | 
| 388 | 
         
            +
                      elif ftype[-1]=='docx':
         
     | 
| 389 | 
         
            +
                        docs_data = openai.docx_to_text(uploaded_file)
         
     | 
| 390 | 
         
            +
                      conversation = [{"role": "system", "content": """
         
     | 
| 391 | 
         
            +
                                    You are a helpful Error sentence finder.
         
     | 
| 392 | 
         
            +
                                    list out the grammatical error sentence in the given text:
         
     | 
| 393 | 
         
            +
                                    """},
         
     | 
| 394 | 
         
            +
                                    {"role": "user", "content": f"```contract: {docs_data}```"}]
         
     | 
| 395 | 
         
            +
                      get_response = openai.get_response(conversation)
         
     | 
| 396 | 
         
            +
                      if get_response == ['', None]:
         
     | 
| 397 | 
         
            +
                          st.write("No Result is founded.")
         
     | 
| 398 | 
         
            +
                      else:
         
     | 
| 399 | 
         
            +
                          with confirmationIncorrect.container():
         
     | 
| 400 | 
         
            +
                              st.write("Incorrect Sentences Extracter:")
         
     | 
| 401 | 
         
            +
                              st.write(get_response)
         
     | 
| 402 | 
         
            +
             
     | 
| 403 | 
         
            +
                              if st.button('Close.'):
         
     | 
| 404 | 
         
            +
                                  confirmationIncorrect.close()
         
     | 
| 405 | 
         
            +
                    else:
         
     | 
| 406 | 
         
            +
                        st.toast("No Document is Uploaded.")
         
     | 
| 407 | 
         
            +
             
     | 
| 408 | 
         
            +
                # Incomplete Sentences
         
     | 
| 409 | 
         
            +
                elif button_value == 'Incomplete Sentences':
         
     | 
| 410 | 
         
            +
                    confirmationIncomplete = Modal("Incomplete Sentences Extracter", key= "Incomplete_Sentences_extract")
         
     | 
| 411 | 
         
            +
                    if uploaded_file is not None:
         
     | 
| 412 | 
         
            +
                      print('File Name : ',uploaded_file.name)
         
     | 
| 413 | 
         
            +
                      ftype=uploaded_file.name.split('.')
         
     | 
| 414 | 
         
            +
                      if ftype[-1]=='pdf':
         
     | 
| 415 | 
         
            +
                        docs_data = openai.pdf_to_text_pypdf2(uploaded_file)
         
     | 
| 416 | 
         
            +
                      elif ftype[-1]=='docx':
         
     | 
| 417 | 
         
            +
                        docs_data = openai.docx_to_text(uploaded_file)
         
     | 
| 418 | 
         
            +
                      conversation = [{"role": "system", "content": """
         
     | 
| 419 | 
         
            +
                                        You are a helpful incomplete sentences finder.
         
     | 
| 420 | 
         
            +
                                        list out the incomplete sentences in the following text:
         
     | 
| 421 | 
         
            +
                                        """},
         
     | 
| 422 | 
         
            +
                                    {"role": "user", "content": f"```contract: {docs_data}```"}]
         
     | 
| 423 | 
         
            +
                      get_response = openai.get_response(conversation)
         
     | 
| 424 | 
         
            +
                      if get_response == ['', None]:
         
     | 
| 425 | 
         
            +
                          st.write("No Result is founded.")
         
     | 
| 426 | 
         
            +
                      else:
         
     | 
| 427 | 
         
            +
                          with confirmationIncomplete.container():
         
     | 
| 428 | 
         
            +
                              st.write("Incomplete Sentences Extracter:")
         
     | 
| 429 | 
         
            +
                              st.write(get_response)
         
     | 
| 430 | 
         
            +
             
     | 
| 431 | 
         
            +
                              if st.button('Close.'):
         
     | 
| 432 | 
         
            +
                                  confirmationIncomplete.close()
         
     | 
| 433 | 
         
            +
                    else:
         
     | 
| 434 | 
         
            +
                        st.toast("No Document is Uploaded.")
         
     | 
| 435 | 
         
            +
             
     | 
| 436 | 
         
            +
                # Aggressive Content
         
     | 
| 437 | 
         
            +
                elif button_value == 'Aggressive Content':
         
     | 
| 438 | 
         
            +
                  confirmationAgg = Modal("Aggressive content Extracter", key= "Aggressive_content_extract")
         
     | 
| 439 | 
         
            +
                  if uploaded_file is not None:
         
     | 
| 440 | 
         
            +
                    print('File Name : ',uploaded_file.name)
         
     | 
| 441 | 
         
            +
                    ftype=uploaded_file.name.split('.')
         
     | 
| 442 | 
         
            +
                    if ftype[-1]=='pdf':
         
     | 
| 443 | 
         
            +
                      docs_data = openai.pdf_to_text_pypdf2(uploaded_file)
         
     | 
| 444 | 
         
            +
                    elif ftype[-1]=='docx':
         
     | 
| 445 | 
         
            +
                      docs_data = openai.docx_to_text(uploaded_file)
         
     | 
| 446 | 
         
            +
                    conversation = [{"role": "system", "content": """
         
     | 
| 447 | 
         
            +
                                  You are a helpful Keywords Extracter..
         
     | 
| 448 | 
         
            +
                                  analyze the given contract and Extract Keywords for following contract in triple backticks. tags should be bullet points.contract :
         
     | 
| 449 | 
         
            +
                                  """},
         
     | 
| 450 | 
         
            +
                                  {"role": "user", "content": f"```contract: {docs_data}```"}]
         
     | 
| 451 | 
         
            +
                    get_response = openai.get_response(conversation)
         
     | 
| 452 | 
         
            +
                    if get_response == ['', None]:
         
     | 
| 453 | 
         
            +
                        st.write("No Result is founded.")
         
     | 
| 454 | 
         
            +
                    else:
         
     | 
| 455 | 
         
            +
                        with confirmationAgg.container():
         
     | 
| 456 | 
         
            +
                            st.write("Aggressive content Extracter:")
         
     | 
| 457 | 
         
            +
                            st.write(get_response)
         
     | 
| 458 | 
         
            +
             
     | 
| 459 | 
         
            +
                            if st.button('Close.'):
         
     | 
| 460 | 
         
            +
                                confirmationAgg.close()
         
     | 
| 461 | 
         
            +
                  else:
         
     | 
| 462 | 
         
            +
                      st.toast("No Document is Uploaded.")
         
     | 
| 463 | 
         
            +
             
     | 
| 464 | 
         
            +
                # Contract Generator
         
     | 
| 465 | 
         
            +
                elif button_value == 'Contract Generator':
         
     | 
| 466 | 
         
            +
                    confirmationEdit = Modal("Contract Generator", key= "contractgen")
         
     | 
| 467 | 
         
            +
                    get_response=''
         
     | 
| 468 | 
         
            +
                    contract_info=st.text_input("Enter Contract info")
         
     | 
| 469 | 
         
            +
                    if contract_info!='':
         
     | 
| 470 | 
         
            +
                        conversation = [{"role": "system", "content": """You are a helpful assistant. Your task is creating a complete contract with important terms and condiations based on the contract information and type.
         
     | 
| 471 | 
         
            +
                            the contract type given by user.
         
     | 
| 472 | 
         
            +
                            generate a contract :
         
     | 
| 473 | 
         
            +
                            """},
         
     | 
| 474 | 
         
            +
                            {"role": "user", "content": f"```content: {contract_info}```"}]
         
     | 
| 475 | 
         
            +
                        get_response = openai.get_response(conversation)
         
     | 
| 476 | 
         
            +
                        if get_response != '':
         
     | 
| 477 | 
         
            +
                            with confirmationEdit.container():
         
     | 
| 478 | 
         
            +
                                st.write("Contract Template")
         
     | 
| 479 | 
         
            +
                                st.write(get_response)
         
     | 
| 480 | 
         
            +
                                if st.button('Exit'):
         
     | 
| 481 | 
         
            +
                                    confirmationEdit.close()
         
     | 
| 482 | 
         
            +
                    else:
         
     | 
| 483 | 
         
            +
                        st.toast("Please Enter Contract Info")
         
     | 
| 484 | 
         
            +
             
     | 
| 485 | 
         
            +
            elif selected_main_option == "Update Find":
         
     | 
| 486 | 
         
            +
                processor = PDFDocumentProcessor()
         
     | 
| 487 | 
         
            +
                processor.file_uploaders()
         
     | 
| 488 | 
         
            +
             
     | 
| 489 | 
         
            +
                if processor.uploaded_agreement and processor.uploaded_template:
         
     | 
| 490 | 
         
            +
                    processor.save_uploaded_files()
         
     | 
| 491 | 
         
            +
             
     | 
| 492 | 
         
            +
            elif selected_main_option == "Comparizer":
         
     | 
| 493 | 
         
            +
                confirmationEdit = Modal("Contract Comparizer", key= "popUp_edit")
         
     | 
| 494 | 
         
            +
                col1, col2 = st.columns(2)
         
     | 
| 495 | 
         
            +
                # Clear the templates and contracts folders before uploading new files
         
     | 
| 496 | 
         
            +
                templates_folder = './templates'
         
     | 
| 497 | 
         
            +
                contracts_folder = './contracts'
         
     | 
| 498 | 
         
            +
                SimilarityCalculator.clear_folder(templates_folder)
         
     | 
| 499 | 
         
            +
                SimilarityCalculator.clear_folder(contracts_folder)
         
     | 
| 500 | 
         
            +
             
     | 
| 501 | 
         
            +
                with col1:
         
     | 
| 502 | 
         
            +
                    st.header("Upload Templates")
         
     | 
| 503 | 
         
            +
                    uploaded_files_templates = st.file_uploader("PDF Template", accept_multiple_files=True, type=['pdf'])
         
     | 
| 504 | 
         
            +
                    os.makedirs(templates_folder, exist_ok=True)
         
     | 
| 505 | 
         
            +
                    for uploaded_file in uploaded_files_templates:
         
     | 
| 506 | 
         
            +
                        if SimilarityCalculator.save_uploaded_file(uploaded_file, templates_folder):
         
     | 
| 507 | 
         
            +
                            st.write(f"Saved: {uploaded_file.name}")
         
     | 
| 508 | 
         
            +
             
     | 
| 509 | 
         
            +
                with col2:
         
     | 
| 510 | 
         
            +
                    st.header("Upload Contracts")
         
     | 
| 511 | 
         
            +
                    uploaded_files_contracts = st.file_uploader("PDF Contracts", key="contracts", accept_multiple_files=True, type=['pdf'])
         
     | 
| 512 | 
         
            +
                    os.makedirs(contracts_folder, exist_ok=True)
         
     | 
| 513 | 
         
            +
                    for uploaded_file in uploaded_files_contracts:
         
     | 
| 514 | 
         
            +
                        if SimilarityCalculator.save_uploaded_file(uploaded_file, contracts_folder):
         
     | 
| 515 | 
         
            +
                            st.write(f"Saved: {uploaded_file.name}")
         
     | 
| 516 | 
         
            +
             
     | 
| 517 | 
         
            +
                model_name = st.selectbox("Select Model", ['sentence-transformers/multi-qa-mpnet-base-dot-v1','sentence-transformers/multi-qa-MiniLM-L6-cos-v1',], index=0)
         
     | 
| 518 | 
         
            +
             
     | 
| 519 | 
         
            +
                if st.button("Compute Similarities"):
         
     | 
| 520 | 
         
            +
                    pdf_processor = PDFProcessor()
         
     | 
| 521 | 
         
            +
                    embedding_processor = EmbeddingsProcessor(model_name)
         
     | 
| 522 | 
         
            +
             
     | 
| 523 | 
         
            +
                    # Process templates
         
     | 
| 524 | 
         
            +
                    template_files = [os.path.join(templates_folder, f) for f in os.listdir(templates_folder)]
         
     | 
| 525 | 
         
            +
                    template_texts = [pdf_processor.extract_text_from_pdfs([f])[0] for f in template_files if pdf_processor.extract_text_from_pdfs([f])]
         
     | 
| 526 | 
         
            +
                    template_embeddings = embedding_processor.get_embeddings(template_texts)
         
     | 
| 527 | 
         
            +
             
     | 
| 528 | 
         
            +
                    # Process contracts
         
     | 
| 529 | 
         
            +
                    contract_files = [os.path.join(contracts_folder, f) for f in os.listdir(contracts_folder)]
         
     | 
| 530 | 
         
            +
                    contract_texts = [pdf_processor.extract_text_from_pdfs([f])[0] for f in contract_files if pdf_processor.extract_text_from_pdfs([f])]
         
     | 
| 531 | 
         
            +
                    contract_embeddings = embedding_processor.get_embeddings(contract_texts)
         
     | 
| 532 | 
         
            +
             
     | 
| 533 | 
         
            +
                    # Compute similarities
         
     | 
| 534 | 
         
            +
                    similarities = SimilarityCalculator.compute_similarity(template_embeddings, contract_embeddings)
         
     | 
| 535 | 
         
            +
             
     | 
| 536 | 
         
            +
                    # Display results in a table format
         
     | 
| 537 | 
         
            +
                    similarity_data = []
         
     | 
| 538 | 
         
            +
                    for i, contract_file in enumerate(contract_files):
         
     | 
| 539 | 
         
            +
                        row = [i + 1, os.path.basename(contract_file)]  # SI No and contract file name
         
     | 
| 540 | 
         
            +
                        for j in range(len(template_files)):
         
     | 
| 541 | 
         
            +
                            if j < similarities.shape[1] and i < similarities.shape[0]:  # Check if indices are within bounds
         
     | 
| 542 | 
         
            +
                                row.append(f"{similarities[i, j] * 100:.2f}%")  # Format as percentage
         
     | 
| 543 | 
         
            +
                            else:
         
     | 
| 544 | 
         
            +
                                row.append("N/A")  # Handle out-of-bounds indices gracefully
         
     | 
| 545 | 
         
            +
                        similarity_data.append(row)
         
     | 
| 546 | 
         
            +
             
     | 
| 547 | 
         
            +
                    # Create a DataFrame for the table
         
     | 
| 548 | 
         
            +
                    columns = ["SI No", "Contract"] + [os.path.basename(template_files[j]) for j in range(len(template_files))]
         
     | 
| 549 | 
         
            +
                    similarity_df = pd.DataFrame(similarity_data, columns=columns)
         
     | 
| 550 | 
         
            +
                    if similarity_df.empty:
         
     | 
| 551 | 
         
            +
                        st.write("No similarities computed.")
         
     | 
| 552 | 
         
            +
                    else:
         
     | 
| 553 | 
         
            +
                        with confirmationEdit.container():
         
     | 
| 554 | 
         
            +
                            st.write("Similarity Scores Table:")
         
     | 
| 555 | 
         
            +
                            st.table(similarity_df.style.hide(axis="index"))
         
     | 
| 556 | 
         
            +
             
     | 
| 557 | 
         
            +
                            if st.button('Close Window'):
         
     | 
| 558 | 
         
            +
                                confirmationEdit.close()
         
     | 
| 559 | 
         
            +
             
     | 
| 560 | 
         
            +
                    submitted = st.button("Show Result")
         
     | 
| 561 | 
         
            +
                    if submitted:
         
     | 
| 562 | 
         
            +
                          confirmationEdit.open()
         
     | 
| 563 | 
         
            +
                    if confirmationEdit.is_open():
         
     | 
| 564 | 
         
            +
                        with confirmationEdit.container():
         
     | 
| 565 | 
         
            +
                            st.write("Similarity Scores Table:")
         
     | 
| 566 | 
         
            +
                            st.table(similarity_df.style.hide(axis="index"))
         
     | 
| 567 | 
         
            +
             
     | 
| 568 | 
         
            +
                            if st.button('Close Result'):
         
     | 
| 569 | 
         
            +
                                confirmationEdit.close()
         
     |