Spaces:
Sleeping
Sleeping
File size: 1,093 Bytes
b58332e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | import streamlit as st
import pandas as pd
import ftfy
def fix_complex_encoding(text):
try:
# First, try to fix text using ftfy
fixed_text = ftfy.fix_text(text)
# Additional encoding and decoding steps to handle more cases
fixed_text = (fixed_text.encode('latin1', errors='ignore')
.decode('utf-8', errors='ignore'))
return fixed_text
except Exception as e:
return text
def process_dataframe(df):
return df.applymap(fix_complex_encoding)
st.title("CSV Encoding Fixer")
uploaded_file = st.file_uploader("Upload a CSV file", type="csv")
if uploaded_file is not None:
df = pd.read_csv(uploaded_file, dtype=str)
st.write("Original Data:")
st.dataframe(df)
processed_df = process_dataframe(df)
st.write("Processed Data:")
st.dataframe(processed_df)
output_csv = processed_df.to_csv(index=False).encode('utf-8')
st.download_button(
label="Download Processed CSV",
data=output_csv,
file_name='processed_file.csv',
mime='text/csv'
) |