Spaces:
				
			
			
	
			
			
		Runtime error
		
	
	
	
			
			
	
	
	
	
		
		
		Runtime error
		
	Update app.py
Browse files
    	
        app.py
    CHANGED
    
    | @@ -12,7 +12,9 @@ from langchain.retrievers import BM25Retriever, EnsembleRetriever | |
| 12 | 
             
            from langchain.schema import Document
         | 
| 13 | 
             
            from langchain.vectorstores import Chroma
         | 
| 14 | 
             
            from langchain.embeddings import HuggingFaceEmbeddings
         | 
| 15 | 
            -
             | 
|  | |
|  | |
| 16 |  | 
| 17 | 
             
            def util_upload_file_and_return_list_docs(uploaded_files):
         | 
| 18 | 
             
                #util_del_cwd()
         | 
| @@ -130,10 +132,21 @@ with st.form("my_form"): | |
| 130 | 
             
                list_save_path = []
         | 
| 131 | 
             
                uploaded_files = st.file_uploader("Choose file(s)", accept_multiple_files=True)
         | 
| 132 | 
             
                print('uploaded_files ', uploaded_files)
         | 
| 133 | 
            -
                submitted = st.form_submit_button(" | 
|  | |
|  | |
|  | |
| 134 |  | 
| 135 | 
             
                if submitted and (uploaded_files is not None):
         | 
| 136 | 
             
                    list_docs, list_save_path = util_upload_file_and_return_list_docs(uploaded_files)
         | 
| 137 | 
             
                    # print('list_docs ' ,list_docs)
         | 
| 138 | 
             
                    # print('list_save_path ' , list_save_path)
         | 
| 139 | 
             
                    passage_documents = util_get_list_page_and_passage(list_docs, list_save_path)
         | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 12 | 
             
            from langchain.schema import Document
         | 
| 13 | 
             
            from langchain.vectorstores import Chroma
         | 
| 14 | 
             
            from langchain.embeddings import HuggingFaceEmbeddings
         | 
| 15 | 
            +
            from setfit import SetFitModel
         | 
| 16 | 
            +
            # Download from the 🤗 Hub
         | 
| 17 | 
            +
            clause_model = SetFitModel.from_pretrained("scholarly360/setfit-contracts-clauses")
         | 
| 18 |  | 
| 19 | 
             
            def util_upload_file_and_return_list_docs(uploaded_files):
         | 
| 20 | 
             
                #util_del_cwd()
         | 
|  | |
| 132 | 
             
                list_save_path = []
         | 
| 133 | 
             
                uploaded_files = st.file_uploader("Choose file(s)", accept_multiple_files=True)
         | 
| 134 | 
             
                print('uploaded_files ', uploaded_files)
         | 
| 135 | 
            +
                submitted = st.form_submit_button("Calculate")
         | 
| 136 | 
            +
             | 
| 137 | 
            +
                my_list_structure = []
         | 
| 138 | 
            +
                import pandas as pd
         | 
| 139 |  | 
| 140 | 
             
                if submitted and (uploaded_files is not None):
         | 
| 141 | 
             
                    list_docs, list_save_path = util_upload_file_and_return_list_docs(uploaded_files)
         | 
| 142 | 
             
                    # print('list_docs ' ,list_docs)
         | 
| 143 | 
             
                    # print('list_save_path ' , list_save_path)
         | 
| 144 | 
             
                    passage_documents = util_get_list_page_and_passage(list_docs, list_save_path)
         | 
| 145 | 
            +
                    for passage_document in passage_documents:
         | 
| 146 | 
            +
                        text = passage_document.page_content
         | 
| 147 | 
            +
                        metadata = passage_document.metadata
         | 
| 148 | 
            +
                        preds = model(text)
         | 
| 149 | 
            +
                        my_list_structure.append({"text": text, "metadata": metadata,"preds":preds })
         | 
| 150 | 
            +
             | 
| 151 | 
            +
                df = pd.DataFrame(my_list_structure)
         | 
| 152 | 
            +
                df
         | 
