firqaaa commited on
Commit
90e750f
·
1 Parent(s): b71a508

update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -8
app.py CHANGED
@@ -1,4 +1,5 @@
1
  import os
 
2
  import time
3
  import json
4
  import glob
@@ -28,6 +29,7 @@ Entrez.email = "[email protected]"
28
  Entrez.api_key = "3d7a71231fe7f2d2bd7599e022535199a908"
29
 
30
  fold = -1
 
31
  # chunk_size = 8000
32
 
33
  st.cache_data()
@@ -219,19 +221,22 @@ if uploaded_file:
219
  })
220
  except Exception as e:
221
  print(e)
222
- # result = pd.DataFrame(L)
223
  st.dataframe(pd.DataFrame(L))
224
- csv = convert_df(pd.DataFrame(L))
 
 
 
 
225
 
226
  st.download_button(
227
  label="Save Result",
228
- data=csv,
229
- file_name=str(uploaded_file.name).replace('.pdf', ''),
230
- mime='text/csv'
231
  )
232
 
233
- except json.JSONDecodeError:
234
  st.write("Sorry, we are experiencing difficulties in extracting the information. Please try again with different context length.")
235
- # st.write(e)
236
- except:
237
  st.write("Sorry, we are experiencing difficulties in extracting the information. Please ensure that you input an uncorrupted file.")
 
1
  import os
2
+ import io
3
  import time
4
  import json
5
  import glob
 
29
  Entrez.api_key = "3d7a71231fe7f2d2bd7599e022535199a908"
30
 
31
  fold = -1
32
+ buffer = io.BytesIO()
33
  # chunk_size = 8000
34
 
35
  st.cache_data()
 
221
  })
222
  except Exception as e:
223
  print(e)
224
+ # # result = pd.DataFrame(L)
225
  st.dataframe(pd.DataFrame(L))
226
+ # csv = convert_df(pd.DataFrame(L))
227
+ with pd.ExcelWriter(buffer, engine='xlsxwriter') as writer:
228
+ # Write each dataframe to a different worksheet
229
+ pd.DataFrame(L).to_excel(writer, sheet_name='Result')
230
+ writer.close()
231
 
232
  st.download_button(
233
  label="Save Result",
234
+ data=buffer,
235
+ file_name=str(uploaded_file.name).replace('.pdf', '') + '.xlsx',
236
+ mime='application/vnd.ms-excel'
237
  )
238
 
239
+ except json.JSONDecodeError as j:
240
  st.write("Sorry, we are experiencing difficulties in extracting the information. Please try again with different context length.")
241
+ except Exception as e:
 
242
  st.write("Sorry, we are experiencing difficulties in extracting the information. Please ensure that you input an uncorrupted file.")