import streamlit as st import pandas as pd from group import CSVtoXMLgroup from jv import journal_vouchers from sale import CSVtoXMLsale from tally import CSVtoXMLtally from payment import CSVtoXMLpayment from cn import CSVtoXMLcn from ledgers import CSVtoXMLledger from dn import debit_note from pixel_sale import CSVtoXMLpixel from alter_ledgers import CSVtoXMLalter from pixel_bin_cn import CSVtoXMLbin import os import tempfile import base64 # URL of your background image background_image_url = "https://media2.giphy.com/media/v1.Y2lkPTc5MGI3NjExY3Yxdzl2ZzZoa2N0amdnNHVsMjF4bmxudHQ1ZGN3MmpheHh6aXN6cyZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/ENeLuI1PyqUnJv4NMl/giphy.webp" # Replace this with the direct image URL # Inject CSS with Streamlit st.markdown( f""" """, unsafe_allow_html=True ) # # Custom gradient title # text_0 = """ #
#

CSV to XML converter

#
# """ # # Display the text with the increased font size # st.markdown(text_0, unsafe_allow_html=True) st.write("") st.write("") st.write("") st.write("") st.write("") st.write("") st.write("") st.write("") col1, col2, col3 = st.columns([25.0, 0.01, 1.0]) with col1: text = """
Transform CSV to Tally XML seamlessly.
""" # Display the text with the increased font size st.markdown(text, unsafe_allow_html=True) st.write('') st.write('') text_2 = """
Currently supporting XML conversion for the CSV templates listed in the dropdown
""" st.markdown(text_2, unsafe_allow_html= True) options = st.selectbox("Please select a CSV template", ['', 'Alter Ledgers','Credit Note', 'Debit Note','Group Creation','Journal Entries','Ledger Creation','Payment Entries', 'Export Credit Note', 'Export Sale', 'Sale', 'Purchase']) if options == 'Alter Ledgers': df = pd.read_csv('alter_ledgers.csv') df = df.head(1) st.dataframe(df) csv = df.to_csv(index = False) st.download_button( label = "Download template", data = csv, file_name= 'alter_ledgers.csv', mime = 'text/csv' ) elif options == 'Credit Note': df = pd.read_csv('cn.csv') df = df.head(1) st.dataframe(df) csv = df.to_csv(index = False) st.download_button( label = "Download template", data = csv, file_name= 'cn.csv', mime = 'text/csv' ) elif options == 'Debit Note': df = pd.read_csv('dn.csv') df = df.head(1) st.dataframe(df) csv = df.to_csv(index = False) st.download_button( label = "Download template", data = csv, file_name= 'dn.csv', mime = 'text/csv' ) elif options == 'Group Creation': df = pd.read_csv('group.csv') df = df.head(1) st.dataframe(df) csv = df.to_csv(index = False) st.download_button( label = "Download template", data = csv, file_name= 'group.csv', mime = 'text/csv' ) elif options == 'Journal Entries': df = pd.read_csv('jv.csv') df = df.head(1) st.dataframe(df) csv = df.to_csv(index = False) st.download_button( label = "Download template", data = csv, file_name= 'jv.csv', mime = 'text/csv' ) elif options == 'Ledger Creation': df = pd.read_csv('ledgers.csv') df = df.head(1) st.dataframe(df) csv = df.to_csv(index = False) st.download_button( label = "Download template", data = csv, file_name= 'ledgers.csv', mime = 'text/csv' ) elif options == 'Payment Entries': df = pd.read_csv('payment.csv') df = df.head(1) st.dataframe(df) csv = df.to_csv(index = False) st.download_button( label = "Download template", data = csv, file_name= 'payment.csv', mime = 'text/csv' ) elif options == 'Export Credit Note': df = pd.read_csv('pixel_bin_cn.csv') df = df.head(1) st.dataframe(df) csv = df.to_csv(index = False) st.download_button( label = "Download template", data = csv, file_name= 'pixel_bin_cn.csv', mime = 'text/csv' ) elif options == 'Export Sale': df = pd.read_csv('pixel_sale.csv') df = df.head(1) st.dataframe(df) csv = df.to_csv(index = False) st.download_button( label = "Download template", data = csv, file_name= 'pixel_sale.csv', mime = 'text/csv' ) elif options == 'Sale': df = pd.read_csv('sale.csv') df = df.head(1) st.dataframe(df) csv = df.to_csv(index = False) st.download_button( label = "Download template", data = csv, file_name= 'sale.csv', mime = 'text/csv' ) elif options == 'Purchase': df = pd.read_csv('tally.csv') df = df.head(1) st.dataframe(df) csv = df.to_csv(index = False) st.download_button( label = "Download template", data = csv, file_name= 'tally.csv', mime = 'text/csv' ) # Upload file uploaded_file = st.file_uploader("Choose a CSV file", type='csv') if uploaded_file is not None: try: # Save the uploaded file to a temporary file with tempfile.NamedTemporaryFile(delete=False, suffix='.csv') as temp_csv_file: temp_csv_path = temp_csv_file.name temp_csv_file.write(uploaded_file.read()) st.write(f'Temporary CSV file path: {temp_csv_path}') # Debug print if uploaded_file.name.lower() == 'group.csv': # Process Group CSV file output_file = CSVtoXMLgroup(temp_csv_path) file_label = 'Group XML' elif uploaded_file.name.lower() == 'jv.csv': # Process Journal Vouchers CSV file output_file = journal_vouchers(temp_csv_path) file_label = 'Journal Vouchers XML' elif uploaded_file.name.lower() == 'sale.csv': # Process Sale CSV file output_file = CSVtoXMLsale(temp_csv_path) file_label = 'Sale XML' elif uploaded_file.name.lower() == 'tally.csv': # Process Tally CSV file output_file = CSVtoXMLtally(temp_csv_path) file_label = 'Tally XML' elif uploaded_file.name.lower() == 'payment.csv': # Process Payment CSV file output_file = CSVtoXMLpayment(temp_csv_path) file_label = 'Payment XML' elif uploaded_file.name.lower() == 'cn.csv': # Process CN CSV file output_file = CSVtoXMLcn(temp_csv_path) file_label = 'CN XML' elif uploaded_file.name.lower() == 'ledgers.csv': # Process Ledger CSV file output_file = CSVtoXMLledger(temp_csv_path) file_label = 'Ledger XML' elif uploaded_file.name.lower() == 'dn.csv': # Process Debit Note CSV file output_file = debit_note(temp_csv_path) file_label = 'Debit Note XML' elif uploaded_file.name.lower() == 'pixel_sale.csv': # Process Pixel Sale CSV file output_file = CSVtoXMLpixel(temp_csv_path) file_label = 'Pixel Sale XML' elif uploaded_file.name.lower() == 'alter_ledgers.csv': # Process Alter Ledgers CSV file output_file = CSVtoXMLalter(temp_csv_path) file_label = 'Alter Ledger XML' elif uploaded_file.name.lower() == 'pixel_bin_cn.csv': # Process Pixel Bin CN CSV file output_file = CSVtoXMLbin(temp_csv_path) file_label = 'Pixel Bin CN XML' else: st.error('Please upload a valid CSV file named group.csv, jv.csv, or sale.csv') output_file = None if output_file and os.path.exists(output_file): # Read the file and encode it in base64 with open(output_file, 'rb') as file: file_data = file.read() b64_file_data = base64.b64encode(file_data).decode() # Provide a download link with the styled button download_link = f""" Download {file_label} """ st.markdown(download_link, unsafe_allow_html=True) else: st.error('No output file was created.') except Exception as e: st.error(f'Error: {e}') finally: # Clean up temporary files if os.path.exists(temp_csv_path): os.remove(temp_csv_path) if output_file and os.path.exists(output_file): os.remove(output_file) with col3: st.image("tally_prime_logo.png")