Spaces:
Running
Running
Update ChemInsight.py
Browse files469 unmodified lines470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504469 unmodified lineselse:st.write(" ")if add_selectbox2 == "2-D Structure":# Sidebarwith st.sidebar.subheader('3. Upload your CSV data'):uploaded_file = st.sidebar.file_uploader("Upload your input CSV file containing 'SMILES' as one column of molecular SMILES", type=["csv"])st.sidebar.markdown("""[Example CSV input file](https://github.com/DivyaKarade/Example-.csv-input-files--AIDrugApp-v1.2/blob/main/smiles.csv)""")if uploaded_file is not None:# Read CSV data@st.cache_datadef load_csv():csv = pd.read_csv(uploaded_file)return csvdf1 = load_csv()df2 = df1.iloc[:, 0:]X = df2# Write CSV datadf2.to_csv('molecule.smi', sep='\t', header=False, index=False)st.subheader('Uploaded data')st.write(df2)smile = df2['SMILES'].valuesif st.sidebar.button("๐ GET STRUCTURE"):st.subheader('2-D structure')# raw_html = mols2grid.display(df2, mapping={"smiles": "SMILES"}, subset=["img", "iupac_name"], tooltip=["molecular_formula", "inchikey"])._repr_html_()raw_html = mols2grid.display(df2, mapping={"smiles": "SMILES"},tooltip=["SMILES"])._repr_html_()components.html(raw_html, width=900, height=900, scrolling=True)469 unmodified lines470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522469 unmodified lineselse:st.write(" ")if add_selectbox2 == "2-D Structure":# Sidebarwith st.sidebar.subheader('3. Upload your CSV data'):uploaded_file = st.sidebar.file_uploader("Upload your input CSV file containing 'SMILES' as one column of molecular SMILES", type=["csv"])st.sidebar.markdown("""[Example CSV input file](https://github.com/DivyaKarade/Example-.csv-input-files--AIDrugApp-v1.2/blob/main/smiles.csv)""")if uploaded_file is not None:# Read CSV data@st.cache_datadef load_csv():csv = pd.read_csv(uploaded_file, encoding='utf-8') # Ensure correct encodingreturn csvdf1 = load_csv()# Standardize column names to avoid case-sensitivity issuesdf1.columns = df1.columns.str.strip().str.lower() # Convert all column names to lowercase# Debugging: Print available column namesst.write("Columns in uploaded CSV:", df1.columns.tolist())# Ensure the 'smiles' column existsif 'smiles' not in df1.columns:st.error("Error: Column 'SMILES' not found! Make sure your CSV file contains 'SMILES' as a column.")st.stop() # Stop execution if the column is missingdf2 = df1.copy()# Rename 'smiles' column to 'SMILES' for consistency in mols2griddf2.rename(columns={"smiles": "SMILES"}, inplace=True)# Write CSV datadf2.to_csv('molecule.smi', sep='\t', header=False, index=False)st.subheader('Uploaded data')st.write(df2)smile = df2['SMILES'].values # Extract SMILES columnif st.sidebar.button("๐ GET STRUCTURE"):st.subheader('2-D structure')# Generate molecular structure visualizationraw_html = mols2grid.display(df2, mapping={"smiles": "SMILES"},tooltip=["SMILES"])._repr_html_()components.html(raw_html, width=900, height=900, scrolling=True)
ChemInsight.py+46-28