Spaces:
				
			
			
	
			
			
		Sleeping
		
	
	
	
			
			
	
	
	
	
		
		
		Sleeping
		
	
		Jiang Xiaolan
		
	commited on
		
		
					Commit 
							
							·
						
						1301d4b
	
1
								Parent(s):
							
							23a6a28
								
support convert json to excel and download
Browse files- app.py +31 -0
- requirements.txt +3 -1
    	
        app.py
    CHANGED
    
    | @@ -112,6 +112,22 @@ if clone_repo(): | |
| 112 | 
             
                    st.write("## アップロードされたファイル")
         | 
| 113 | 
             
                    st.image(pil_image, caption="アップロードされたファイル", use_column_width=True)
         | 
| 114 |  | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 115 | 
             
                if text_rec:
         | 
| 116 | 
             
                    with col2:
         | 
| 117 | 
             
                        st.write("## 結果")
         | 
| @@ -126,9 +142,24 @@ if clone_repo(): | |
| 126 |  | 
| 127 | 
             
                            # Simulate OCR result as a JSON object
         | 
| 128 | 
             
                            json_predictions = ia.get_json_result(predictions)
         | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 129 |  | 
| 130 | 
             
                            # After model finishes
         | 
| 131 | 
             
                            status_placeholder.success('ファイルの解析が完了しました!')
         | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 132 |  | 
| 133 | 
             
                            # Display the result
         | 
| 134 | 
             
                            st.write("解析後の内容:")
         | 
|  | |
| 112 | 
             
                    st.write("## アップロードされたファイル")
         | 
| 113 | 
             
                    st.image(pil_image, caption="アップロードされたファイル", use_column_width=True)
         | 
| 114 |  | 
| 115 | 
            +
                if 'json_predictions' in st.session_state:
         | 
| 116 | 
            +
                    prev_json_predictions = st.session_state.json_predictions
         | 
| 117 | 
            +
                    prev_excel_file_path = st.session_state.excel_file_path
         | 
| 118 | 
            +
                    with col2:
         | 
| 119 | 
            +
                        st.write("## 結果")
         | 
| 120 | 
            +
                        # 提供下载链接
         | 
| 121 | 
            +
                        with open(prev_excel_file_path, "rb") as file:
         | 
| 122 | 
            +
                            st.download_button(
         | 
| 123 | 
            +
                                label="Download Excel",
         | 
| 124 | 
            +
                                data=file,
         | 
| 125 | 
            +
                                file_name="output.xlsx",
         | 
| 126 | 
            +
                                mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
         | 
| 127 | 
            +
                            )
         | 
| 128 | 
            +
                        st.write("解析後の内容:")
         | 
| 129 | 
            +
                        st.json(prev_json_predictions)
         | 
| 130 | 
            +
                    
         | 
| 131 | 
             
                if text_rec:
         | 
| 132 | 
             
                    with col2:
         | 
| 133 | 
             
                        st.write("## 結果")
         | 
|  | |
| 142 |  | 
| 143 | 
             
                            # Simulate OCR result as a JSON object
         | 
| 144 | 
             
                            json_predictions = ia.get_json_result(predictions)
         | 
| 145 | 
            +
                            st.session_state.json_predictions = json_predictions
         | 
| 146 | 
            +
                            
         | 
| 147 | 
            +
                            # Convert JSON to Excel
         | 
| 148 | 
            +
                            excel_file_path = "output.xlsx"
         | 
| 149 | 
            +
                            st.session_state.excel_file_path = excel_file_path
         | 
| 150 | 
            +
                            ia.json_to_excel_with_links(json_predictions, excel_file_path)
         | 
| 151 |  | 
| 152 | 
             
                            # After model finishes
         | 
| 153 | 
             
                            status_placeholder.success('ファイルの解析が完了しました!')
         | 
| 154 | 
            +
             | 
| 155 | 
            +
                            # 提供下载链接
         | 
| 156 | 
            +
                            with open(excel_file_path, "rb") as file:
         | 
| 157 | 
            +
                                st.download_button(
         | 
| 158 | 
            +
                                    label="Download Excel",
         | 
| 159 | 
            +
                                    data=file,
         | 
| 160 | 
            +
                                    file_name="output.xlsx",
         | 
| 161 | 
            +
                                    mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
         | 
| 162 | 
            +
                                )
         | 
| 163 |  | 
| 164 | 
             
                            # Display the result
         | 
| 165 | 
             
                            st.write("解析後の内容:")
         | 
    	
        requirements.txt
    CHANGED
    
    | @@ -1,3 +1,5 @@ | |
| 1 | 
             
            surya-ocr==0.4.15
         | 
| 2 | 
             
            pypdfium2==4.30.0
         | 
| 3 | 
            -
            openai==1.35.13
         | 
|  | |
|  | 
|  | |
| 1 | 
             
            surya-ocr==0.4.15
         | 
| 2 | 
             
            pypdfium2==4.30.0
         | 
| 3 | 
            +
            openai==1.35.13
         | 
| 4 | 
            +
            pandas==2.2.2
         | 
| 5 | 
            +
            openpyxl==3.1.5
         | 
