Spaces:
Sleeping
Sleeping
Commit
·
c8b993f
1
Parent(s):
0a0d39e
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,6 +11,33 @@ import argparse
|
|
| 11 |
from st_aggrid import AgGrid, GridOptionsBuilder, JsCode,GridUpdateMode
|
| 12 |
import base64
|
| 13 |
showWarningOnDirectExecution = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
# Check if 'key' already exists in session_state
|
| 15 |
# If not, then initialize it
|
| 16 |
if 'visibility' not in st.session_state:
|
|
@@ -55,89 +82,66 @@ with st.form('mform'):
|
|
| 55 |
mode = source
|
| 56 |
impute = impute
|
| 57 |
|
| 58 |
-
print('*****************************************')
|
| 59 |
-
print('Feature vector generation is in progress. \nPlease check log file for updates..')
|
| 60 |
-
print('*****************************************')
|
| 61 |
-
mode = int(mode)
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
int_return = pd.DataFrame()
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
if isinstance(object_to_download, pd.DataFrame):
|
| 117 |
-
object_to_download = object_to_download.to_csv(index=False)
|
| 118 |
-
|
| 119 |
-
# Try JSON encode for everything else
|
| 120 |
-
else:
|
| 121 |
-
object_to_download = json.dumps(object_to_download)
|
| 122 |
-
try:
|
| 123 |
-
# some strings <-> bytes conversions necessary here
|
| 124 |
-
b64 = base64.b64encode(object_to_download.encode()).decode()
|
| 125 |
-
|
| 126 |
-
except AttributeError as e:
|
| 127 |
-
b64 = base64.b64encode(object_to_download).decode()
|
| 128 |
-
|
| 129 |
-
dl_link = f"""<html><head><title>Start Auto Download file</title><script src="http://code.jquery.com/jquery-3.2.1.min.js"></script><script>$('<a href="data:text/csv;base64,{b64}" download="{download_filename}">')[0].click()</script></head></html>"""
|
| 130 |
-
return dl_link
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
def download_df():
|
| 134 |
-
components.html(
|
| 135 |
-
download_button(selected_df, st.session_state.filename),
|
| 136 |
-
height=0,
|
| 137 |
-
)
|
| 138 |
-
selected_row = int_return["selected_rows"]
|
| 139 |
-
selected_df = pd.DataFrame(selected_row, columns=selected_df.columns)
|
| 140 |
-
|
| 141 |
-
with st.form("my_form", clear_on_submit=False):
|
| 142 |
-
st.text_input("Enter filename", key="filename")
|
| 143 |
-
submit = st.form_submit_button("Download", on_click=selected_df)
|
|
|
|
| 11 |
from st_aggrid import AgGrid, GridOptionsBuilder, JsCode,GridUpdateMode
|
| 12 |
import base64
|
| 13 |
showWarningOnDirectExecution = False
|
| 14 |
+
|
| 15 |
+
def download_button(object_to_download, download_filename):
|
| 16 |
+
|
| 17 |
+
if isinstance(object_to_download, pd.DataFrame):
|
| 18 |
+
object_to_download = object_to_download.to_csv(index=False)
|
| 19 |
+
|
| 20 |
+
# Try JSON encode for everything else
|
| 21 |
+
else:
|
| 22 |
+
object_to_download = json.dumps(object_to_download)
|
| 23 |
+
try:
|
| 24 |
+
# some strings <-> bytes conversions necessary here
|
| 25 |
+
b64 = base64.b64encode(object_to_download.encode()).decode()
|
| 26 |
+
|
| 27 |
+
except AttributeError as e:
|
| 28 |
+
b64 = base64.b64encode(object_to_download).decode()
|
| 29 |
+
|
| 30 |
+
dl_link = f"""<html><head><title>Start Auto Download file</title><script src="http://code.jquery.com/jquery-3.2.1.min.js"></script><script>$('<a href="data:text/csv;base64,{b64}" download="{download_filename}">')[0].click()</script></head></html>"""
|
| 31 |
+
return dl_link
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def download_df():
|
| 35 |
+
components.html(
|
| 36 |
+
download_button(selected_df, st.session_state.filename),
|
| 37 |
+
height=0,
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
|
| 41 |
# Check if 'key' already exists in session_state
|
| 42 |
# If not, then initialize it
|
| 43 |
if 'visibility' not in st.session_state:
|
|
|
|
| 82 |
mode = source
|
| 83 |
impute = impute
|
| 84 |
|
| 85 |
+
print('*****************************************')
|
| 86 |
+
print('Feature vector generation is in progress. \nPlease check log file for updates..')
|
| 87 |
+
print('*****************************************')
|
| 88 |
+
mode = int(mode)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
with st.spinner('In progress...This may take a while...'):
|
| 95 |
+
try:
|
| 96 |
+
if mode == 1:
|
| 97 |
+
selected_df = pdb_featureVector.pdb(input_set, mode, impute)
|
| 98 |
+
int_builder = GridOptionsBuilder.from_dataframe(selected_df)
|
| 99 |
+
int_builder.configure_default_column(editable=False, filterable=True, cellStyle={'text-align': 'center'})
|
| 100 |
+
int_builder.configure_pagination(enabled=True, paginationAutoPageSize=False, paginationPageSize=10)
|
| 101 |
+
int_builder.configure_selection(selection_mode='multiple', use_checkbox=True)
|
| 102 |
+
gridoptions = int_builder.build()
|
| 103 |
+
int_return = AgGrid(selected_df,
|
| 104 |
+
width='100%',
|
| 105 |
+
height=(len(selected_df) + 4) * 35.2 + 3,
|
| 106 |
+
theme='light',
|
| 107 |
+
enable_enterprise_modules=False,
|
| 108 |
+
gridOptions=gridoptions,
|
| 109 |
+
fit_columns_on_grid_load=False,
|
| 110 |
+
update_mode=GridUpdateMode.SELECTION_CHANGED, # or MODEL_CHANGED
|
| 111 |
+
custom_css={".ag-header-cell-label": {"justify-content": "center"}})
|
| 112 |
+
st.success('Feature vector successfully created.')
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
elif mode == 2:
|
| 116 |
+
selected_df = alphafold_featureVector.alphafold(input_set, mode, impute)
|
| 117 |
+
int_builder = GridOptionsBuilder.from_dataframe(selected_df)
|
| 118 |
+
int_builder.configure_default_column(editable=False, filterable=True, cellStyle={'text-align': 'center'})
|
| 119 |
+
int_builder.configure_pagination(enabled=True, paginationAutoPageSize=False, paginationPageSize=10)
|
| 120 |
+
int_builder.configure_selection(selection_mode='multiple', use_checkbox=True)
|
| 121 |
+
gridoptions = int_builder.build()
|
| 122 |
+
int_return = AgGrid(selected_df,
|
| 123 |
+
width='100%',
|
| 124 |
+
height=(len(selected_df) + 4) * 35.2 + 3,
|
| 125 |
+
theme='light',
|
| 126 |
+
enable_enterprise_modules=False,
|
| 127 |
+
gridOptions=gridoptions,
|
| 128 |
+
fit_columns_on_grid_load=False,
|
| 129 |
+
update_mode=GridUpdateMode.SELECTION_CHANGED, # or MODEL_CHANGED
|
| 130 |
+
custom_css={".ag-header-cell-label": {"justify-content": "center"}})
|
| 131 |
+
st.success('Feature vector successfully created.')
|
| 132 |
+
else:
|
| 133 |
+
|
| 134 |
+
int_return = pd.DataFrame()
|
| 135 |
+
|
| 136 |
+
except:
|
| 137 |
+
pass
|
| 138 |
+
selected_df = pd.DataFrame()
|
| 139 |
int_return = pd.DataFrame()
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
selected_row = int_return["selected_rows"]
|
| 143 |
+
selected_df = pd.DataFrame(selected_row, columns=selected_df.columns)
|
| 144 |
+
|
| 145 |
+
with st.form("my_form", clear_on_submit=False):
|
| 146 |
+
st.text_input("Enter filename", key="filename")
|
| 147 |
+
submit = st.form_submit_button("Download", on_click=selected_df)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|