CoolFace
Apppublic

Sowmya15/JsonSQL

sourceHugging Faceopenrailupdated 3y agoView on Hugging Face
0likes
app.py75 linesDownload Raw Back to root
1import streamlit as st2import openpyxl3import pandas as pd4import json 5 6st.set_page_config('JSON REPLACEMENT',layout="wide")7st.markdown("""8        <style>9               .css-18e3th9 {10                    padding-top: 0rem;11                    padding-bottom: 10rem;12                    padding-left: 5rem;13                    padding-right: 5rem;14                }15               .css-1d391kg {16                    padding-top: 3.5rem;17                    padding-right: 1rem;18                    padding-bottom: 3.5rem;19                    padding-left: 1rem;20                }21        </style>22        """, unsafe_allow_html=True)23 24#Title of the page with CSS25 26st.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)27st.markdown('<p class="font">JSON FILE REPLACEMENT</p>', unsafe_allow_html=True) 28 29with st.container():30    col1, col2= st.columns(2)31    with col1:32        data_file=st.file_uploader("Upload Excel file",type=['xlsx'])  33 34    if data_file:35        with col2:36            wb = openpyxl.load_workbook(data_file)37            sheet_selector = st.multiselect("Select sheet:",wb.sheetnames)38 39      40if data_file:41    if len(sheet_selector)==1: 42 43        df1 = pd.read_excel(data_file,sheet_selector[0])44        st.markdown('<p class="font1">COLUMN MAPPING</p>', unsafe_allow_html=True) 45 46        st.dataframe(df1)47 48        col1,col2=st.columns(2)49 50        with col1:51            df1_col=st.multiselect('Replaced From:',df1.columns)52            existing=df1.iloc[:,0]53  54        with col2:55            df2_col=st.multiselect('Replaced To:',df1.columns)56            replaced=df1.iloc[:,1]57 58json_file=st.file_uploader("Upload JSON file",type=['json'])59if json_file is not None:60    jfile=json_file.read() #Read as string 61    jfile=jfile.decode('utf8') #byte to string62    for i in range(len(existing)): #Traverse through the list63        jfile = jfile.replace(existing[i], replaced[i]) 64 65    new_name=st.text_input("Provide Name for the file")66    f_name=new_name+".json"67 68    st.download_button(69    label="Download JSON",70    file_name=f_name,71    mime="application/json",72    data=jfile73    )74 75