Download CSV_UI.py from jkushwaha/streamlit: direct link, hf CLI and curl.
- Browser
- Download file 3.22 kB
-
https://huggingface.co/jkushwaha/streamlit/resolve/main/CSV_UI.py
- Command line
-
hf download hf://jkushwaha/streamlit/CSV_UI.py
-
curl -L -o CSV_UI.py https://huggingface.co/jkushwaha/streamlit/resolve/main/CSV_UI.py
3.22 kB
| import streamlit as st | |
| import pandas as pd | |
| import numpy as np | |
| def highlight_diff1(row, df1, df2, primary_key): | |
| styles = [] | |
| name = row.name | |
| if name in df1.index and name in df2.index: | |
| index1 = df1.index.get_loc(name) | |
| index2 = df2.index.get_loc(name) | |
| for col in df1.columns: | |
| if col != primary_key and df1.iloc[index1][col] != df2.iloc[index2][col]: | |
| styles = ['background-color: green'] * len(row) | |
| break | |
| elif name in df1.index: | |
| styles = ['background-color: yellow'] * len(row) | |
| return styles or [''] * len(row) | |
| def highlight_diff2(row, df1, df2, primary_key): | |
| styles = [] | |
| name = row.name | |
| if name in df1.index and name in df2.index: | |
| index1 = df1.index.get_loc(name) | |
| index2 = df2.index.get_loc(name) | |
| for col in df2.columns: | |
| if col != primary_key and df1.iloc[index1][col] != df2.iloc[index2][col]: | |
| styles = ['background-color: red'] * len(row) | |
| break | |
| elif name in df2.index: | |
| styles = ['background-color: yellow'] * len(row) | |
| return styles or [''] * len(row) | |
| def main(): | |
| st.set_page_config(layout="wide") | |
| st.write("### Input Paths") | |
| df1_path = st.text_input("Enter Auto_CSV Path:") | |
| df2_path = st.text_input("Enter OLD Auto_CSV Path:") | |
| if not df1_path or not df2_path: | |
| st.warning("Please enter both CSVs Paths.") | |
| return | |
| df1 = pd.read_csv(df1_path) | |
| df2 = pd.read_csv(df2_path) | |
| primary_column = 'Name' | |
| common_columns = list(set(df1.columns).intersection(df2.columns)) | |
| common_cols = [x for x in common_columns if x != primary_column] | |
| cols_to_display = st.multiselect("Select Columns to Display", common_cols) | |
| columns_to_display = cols_to_display + [primary_column] | |
| col1_width = st.sidebar.slider("Width of First Column", 0.1, 10.0, 6.5, 0.1) | |
| col2_width = st.sidebar.slider("Width of Second Column", 0.1, 10.0, 6.5, 0.1) | |
| col1, col2 = st.columns([col1_width, col2_width]) | |
| with col1: | |
| st.write("### Display DataFrame 1") | |
| if df1 is not None: | |
| if len(columns_to_display) > 0: | |
| df1_display = df1[columns_to_display].set_index(primary_column) | |
| df1_display_styled = df1_display.style.apply( | |
| lambda x: highlight_diff1(x, df1_display, df2.set_index(primary_column), primary_column), axis=1) | |
| st.dataframe(df1_display_styled) | |
| else: | |
| st.write("No columns selected") | |
| else: | |
| st.write("DataFrame not found") | |
| with col2: | |
| st.write("### Display DataFrame 2") | |
| if df2 is not None: | |
| if len(columns_to_display) > 0: | |
| df2_display = df2[columns_to_display].set_index(primary_column) | |
| df2_display_styled = df2_display.style.apply( | |
| lambda x: highlight_diff2(x, df1.set_index(primary_column), df2_display, primary_column), axis=1) | |
| st.dataframe(df2_display_styled) | |
| else: | |
| st.write("No columns selected") | |
| else: | |
| st.write("DataFrame not found") | |
| if __name__ == "__main__": | |
| main() | |