Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
import json
|
|
|
|
| 4 |
|
| 5 |
# Function to load the .ifs file
|
| 6 |
def load_ifs_file(file):
|
|
@@ -36,14 +37,6 @@ def update_json(json_data, code_neo_list, new_values):
|
|
| 36 |
pass # If the key path doesn't exist, skip it
|
| 37 |
return json_data
|
| 38 |
|
| 39 |
-
# Function to create a downloadable Excel file
|
| 40 |
-
def create_downloadable_excel(template_df, extracted_values):
|
| 41 |
-
template_df["TEXTE_NEO"] = extracted_values
|
| 42 |
-
output = pd.ExcelWriter("extracted_data.xlsx", engine="xlsxwriter")
|
| 43 |
-
template_df.to_excel(output, index=False, sheet_name="profil")
|
| 44 |
-
output.save()
|
| 45 |
-
return output
|
| 46 |
-
|
| 47 |
# Streamlit App
|
| 48 |
st.title("JSON to Excel Mapping and Update")
|
| 49 |
|
|
@@ -74,11 +67,17 @@ if mode == "Extraction Mode":
|
|
| 74 |
# Add extracted values to the Excel template
|
| 75 |
template_df["TEXTE_NEO"] = extracted_values
|
| 76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
# Provide the downloadable file
|
| 78 |
st.success("Data extracted successfully!")
|
| 79 |
st.download_button(
|
| 80 |
label="Download Extracted Excel",
|
| 81 |
-
data=
|
| 82 |
file_name="extracted_data.xlsx",
|
| 83 |
mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
| 84 |
)
|
|
@@ -114,3 +113,4 @@ elif mode == "Update Mode":
|
|
| 114 |
file_name="updated_report.ifs",
|
| 115 |
mime="application/json"
|
| 116 |
)
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
import json
|
| 4 |
+
import io
|
| 5 |
|
| 6 |
# Function to load the .ifs file
|
| 7 |
def load_ifs_file(file):
|
|
|
|
| 37 |
pass # If the key path doesn't exist, skip it
|
| 38 |
return json_data
|
| 39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
# Streamlit App
|
| 41 |
st.title("JSON to Excel Mapping and Update")
|
| 42 |
|
|
|
|
| 67 |
# Add extracted values to the Excel template
|
| 68 |
template_df["TEXTE_NEO"] = extracted_values
|
| 69 |
|
| 70 |
+
# Create an Excel file in memory for download
|
| 71 |
+
output = io.BytesIO()
|
| 72 |
+
with pd.ExcelWriter(output, engine="openpyxl") as writer:
|
| 73 |
+
template_df.to_excel(writer, index=False, sheet_name="profil")
|
| 74 |
+
output.seek(0)
|
| 75 |
+
|
| 76 |
# Provide the downloadable file
|
| 77 |
st.success("Data extracted successfully!")
|
| 78 |
st.download_button(
|
| 79 |
label="Download Extracted Excel",
|
| 80 |
+
data=output,
|
| 81 |
file_name="extracted_data.xlsx",
|
| 82 |
mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
| 83 |
)
|
|
|
|
| 113 |
file_name="updated_report.ifs",
|
| 114 |
mime="application/json"
|
| 115 |
)
|
| 116 |
+
|