Jsonreplacement / app.py
Sowmya15's picture
Upload app.py
b181f80
import streamlit as st
import openpyxl
import pandas as pd
import json
st.set_page_config('JSON REPLACEMENT',layout="wide")
st.markdown("""
<style>
.css-18e3th9 {
padding-top: 0rem;
padding-bottom: 10rem;
padding-left: 5rem;
padding-right: 5rem;
}
.css-1d391kg {
padding-top: 3.5rem;
padding-right: 1rem;
padding-bottom: 3.5rem;
padding-left: 1rem;
}
</style>
""", unsafe_allow_html=True)
#Title of the page with CSS
st.markdown(""" <style> .font {font-size:40px ; font-family: 'Verdana'; color: #000000;} .font1 {font-size:20px ; font-family: 'Verdana'; color: red;} </style> """, unsafe_allow_html=True)
st.markdown('<p class="font">JSON FILE REPLACEMENT</p>', unsafe_allow_html=True)
with st.container():
col1, col2= st.columns(2)
with col1:
data_file=st.file_uploader("Upload Excel file",type=['xlsx'])
if data_file:
with col2:
wb = openpyxl.load_workbook(data_file)
sheet_selector = st.multiselect("Select sheet:",wb.sheetnames)
if data_file:
if len(sheet_selector)==1:
df1 = pd.read_excel(data_file,sheet_selector[0])
st.markdown('<p class="font1">COLUMN MAPPING</p>', unsafe_allow_html=True)
st.dataframe(df1)
col1,col2=st.columns(2)
with col1:
df1_col=st.multiselect('Replaced From:',df1.columns)
existing=df1.iloc[:,0]
with col2:
df2_col=st.multiselect('Replaced To:',df1.columns)
replaced=df1.iloc[:,1]
json_file=st.file_uploader("Upload JSON file",type=['json'])
if json_file is not None:
jfile=json_file.read() #Read as string
jfile=jfile.decode('utf8') #byte to string
for i in range(len(existing)): #Traverse through the list
jfile = jfile.replace(existing[i], replaced[i])
new_name=st.text_input("Provide Name for the file")
f_name=new_name+".json"
st.download_button(
label="Download JSON",
file_name=f_name,
mime="application/json",
data=jfile
)