Spaces:
Sleeping
Sleeping
import gradio as gr | |
import pandas as pd | |
import scipy | |
from utils import * | |
def spm_fn(SPM_path_to_csv, SPM_identifier_column, SPM_sequence_column, SPM_sortby, SPM_sliding_window_min, SPM_sliding_window_max, SPM_min_gap, SPM_max_gap, SPM_S_support_thresh, SPM_I_support_thresh, SPM_dataset_format): | |
spm_params = { | |
"path_to_csv": SPM_path_to_csv.name, | |
"identifier_column": SPM_identifier_column, | |
"sequence_column": SPM_sequence_column, | |
"sortby": SPM_sortby, | |
"sliding_window_min": SPM_sliding_window_min, | |
"sliding_window_max": SPM_sliding_window_max, | |
"min_gap": SPM_min_gap, | |
"max_gap": SPM_max_gap, | |
"S_support_thresh": SPM_S_support_thresh, | |
"I_support_thresh": SPM_I_support_thresh, | |
"dataset_format": SPM_dataset_format | |
} | |
spm_result, occurrence_matrix = SPM(spm_params) | |
spm_result=spm_result.reset_index() | |
spm_result.rename(columns={'index': 'Pattern'}, inplace=True) | |
spm_result.to_csv("spm_result.csv") | |
return "spm_result.csv",spm_result | |
def dsm_fn(DSM_path_to_csv_left, DSM_path_to_csv_right, DSM_identifier_column, DSM_sequence_column, DSM_sortby, DSM_sliding_window_min, DSM_sliding_window_max, DSM_min_gap, DSM_max_gap, DSM_S_support_thresh, DSM_I_support_thresh, DSM_threshold_pvalue, DSM_dataset_format, DSM_test_type): | |
dsm_params = { | |
"path_to_csv_left": DSM_path_to_csv_left.name, | |
"path_to_csv_right": DSM_path_to_csv_right.name, | |
"identifier_column": DSM_identifier_column, | |
"sequence_column": DSM_sequence_column, | |
"sortby": DSM_sortby, | |
"sliding_window_min": DSM_sliding_window_min, | |
"sliding_window_max": DSM_sliding_window_max, | |
"min_gap": DSM_min_gap, | |
"max_gap": DSM_max_gap, | |
"S_support_thresh": DSM_S_support_thresh, | |
"I_support_thresh": DSM_I_support_thresh, | |
"threshold_pvalue": DSM_threshold_pvalue, | |
"dataset_format": DSM_dataset_format, | |
"test_type": DSM_test_type | |
} | |
ptrn_left, ptrn_right, ptrn_both_left, ptrn_both_right, dsm_result = DSM(dsm_params) | |
dsm_result.to_csv("dsm_result.csv") | |
return "dsm_result.csv",dsm_result | |
theme = gr.themes.Base( | |
primary_hue="gray", | |
secondary_hue="orange", | |
neutral_hue="neutral", | |
font=[gr.themes.GoogleFont('Source Sans Pro'), 'ui-sans-serif', gr.themes.GoogleFont('system-ui'), 'sans-serif'], | |
).set( | |
body_background_fill='*primary_200', | |
body_background_fill_dark='*primary_950', | |
body_text_color_dark='*primary_100', | |
body_text_weight='500', | |
embed_radius='*radius_xxl', | |
background_fill_primary='*primary_50', | |
button_shadow='*input_shadow', | |
background_fill_primary_dark='*secondary_800', | |
background_fill_secondary_dark='*primary_200', | |
border_color_accent='*secondary_800', | |
border_color_accent_dark='*secondary_950', | |
border_color_primary='*primary_950', | |
color_accent_soft_dark='*neutral_500', | |
link_text_color='*neutral_900', | |
link_text_color_dark='*primary_200', | |
code_background_fill='*secondary_200', | |
block_background_fill='*body_background_fill', | |
button_border_width='*block_label_border_width', | |
button_primary_text_color_dark='*primary_300', | |
button_secondary_text_color_dark='*table_odd_background_fill', | |
button_secondary_text_color_hover='*button_secondary_background_fill' | |
) | |
def demo(): | |
with gr.Blocks(theme=theme) as demo: | |
gr.Markdown( | |
"""<center><h2>SPM and DSM Implementation in Python</center></h2> | |
<h3>Sequential Pattern Mining (SPM) and Differential Sequential Mining (DSM)</h3> | |
""" | |
) | |
with gr.Tab("SPM"): | |
with gr.Row(): | |
spm_file = gr.File(label="Upload CSV file") | |
with gr.Accordion("Advanced options", open=False): | |
with gr.Row(): | |
identifier_column = gr.Textbox(label="Identifier Column", value="Identifier") | |
with gr.Row(): | |
sequence_column = gr.Textbox(label="Sequence Column", value="Sequence") | |
with gr.Row(): | |
sortby = gr.Dropdown(label="Sort By", choices=["S-Support", "I-Support"], value="S-Support") | |
with gr.Row(): | |
sliding_window_min = gr.Number(label="Sliding Window Min", value=1) | |
with gr.Row(): | |
sliding_window_max = gr.Number(label="Sliding Window Max", value=4) | |
with gr.Row(): | |
min_gap = gr.Number(label="Min Gap", value=1) | |
with gr.Row(): | |
max_gap = gr.Number(label="Max Gap", value=12) | |
with gr.Row(): | |
S_support_thresh = gr.Number(label="S Support Threshold", value=0.4) | |
with gr.Row(): | |
I_support_thresh = gr.Number(label="I Support Threshold", value=0) | |
with gr.Row(): | |
dataset_format = gr.Number(label="Dataset Format", value=0) | |
with gr.Row(): | |
spm_result=gr.File(label="SPM result") | |
with gr.Row(): | |
spm_dataframe=gr.Dataframe() | |
spm_submit = gr.Button("Generate SPM Result...") | |
with gr.Tab("DSM"): | |
with gr.Row(): | |
dsm_left_file = gr.File(label="Upload Left Dataset CSV file") | |
dsm_right_file = gr.File(label="Upload Right Dataset CSV file") | |
with gr.Accordion("Advanced options", open=False): | |
with gr.Row(): | |
identifier_column_dsm = gr.Textbox(label="Identifier Column", value="Identifier") | |
with gr.Row(): | |
sequence_column_dsm = gr.Textbox(label="Sequence Column", value="Sequence") | |
with gr.Row(): | |
sortby_dsm = gr.Dropdown(label="Sort By", choices=["S-Support", "I-Support"], value="S-Support") | |
with gr.Row(): | |
sliding_window_min_dsm = gr.Number(label="Sliding Window Min", value=1) | |
with gr.Row(): | |
sliding_window_max_dsm = gr.Number(label="Sliding Window Max", value=1) | |
with gr.Row(): | |
min_gap_dsm = gr.Number(label="Min Gap", value=1) | |
with gr.Row(): | |
max_gap_dsm = gr.Number(label="Max Gap", value=12) | |
with gr.Row(): | |
S_support_thresh_dsm = gr.Number(label="S Support Threshold", value=0.4) | |
with gr.Row(): | |
I_support_thresh_dsm = gr.Number(label="I Support Threshold", value=0) | |
with gr.Row(): | |
threshold_pvalue = gr.Number(label="Threshold P-value", value=0.1) | |
with gr.Row(): | |
dataset_format_dsm = gr.Number(label="Dataset Format", value=0) | |
with gr.Row(): | |
test_type = gr.Dropdown(label="Test Type", choices=["poisson_means_test", "ttest_ind", "mannwhitneyu", "bws_test", "ranksums", "brunnermunzel", "mood", "ansari", "cramervonmises_2samp", "epps_singleton_2samp", "ks_2samp", "kstest"], value="ttest_ind") | |
with gr.Row(): | |
dsm_result=gr.File(label="DSM result") | |
with gr.Row(): | |
dsm_dataframe=gr.Dataframe() | |
dsm_submit = gr.Button("Generate DSM Result...") | |
spm_submit.click(spm_fn, \ | |
inputs=[spm_file, identifier_column, sequence_column, sortby, sliding_window_min, sliding_window_max, min_gap, max_gap, S_support_thresh, I_support_thresh, dataset_format], \ | |
outputs=[spm_result,spm_dataframe]) | |
dsm_submit.click(dsm_fn, \ | |
inputs=[dsm_left_file, dsm_right_file, identifier_column_dsm, sequence_column_dsm, sortby_dsm, sliding_window_min_dsm, sliding_window_max_dsm, min_gap_dsm, max_gap_dsm, S_support_thresh_dsm, I_support_thresh_dsm, threshold_pvalue, dataset_format_dsm, test_type], \ | |
outputs=[dsm_result,dsm_dataframe]) | |
demo.queue().launch(debug=True,share=True) | |
#gr.themes.builder() | |
if __name__ == "__main__": | |
demo() | |