MLRG_Front_End / app.py
Vish2005's picture
Update app.py
923a604 verified
import gradio as gr
import json
from itertools import product
import subprocess # assuming you need this for calling run_on_scc.sh
# Helper function to run the analysis
def run_analysis(datasets, machines):
selected_datasets = datasets # it's already a list
selected_machines = machines # it's already a list
if not selected_datasets:
return "Please select at least one dataset."
if not selected_machines:
return "Please select at least one machine."
configurations = []
for dataset, machine in product(selected_datasets, selected_machines):
config = {
"Dataset": dataset, "Binary": "True", "Image": "False", "TM_use": False, "value": "None", "Interpolation_value": "None", "Noise": False, "noise_type": False, "augmentation": False, "shear_factor": "None", "shear_prop": 0, "crop_scale_factor": "None", "crop_scale_prop": 0, "flip_code": "None", "flip_prop": 0, "rotation_angle": "None", "rotate_prop": 0, "color_number": "None", "color_prop": 0, "blur_param": "None", "blur_prop": 0, "features": "False", "glcm_distance": "None", "glcm_angle": "None", "glcm_prop": 0, "lbp_radius": "None", "lbp_prop": 0, "haralick_prop": 0, "Machine": machine, "lr": "None", "epochs": "None"
}
configurations.append(config)
filepath = "results/models-parameters_list.txt"
output_filepath = "results/evaluation_scores.txt"
with open(filepath, 'w') as f:
for config in configurations:
f.write(json.dumps(config))
f.write("\n\n")
# Call the SCC script and return computing status
result = subprocess.run(["ssh", "-i", "~/.ssh/gradio_key", "[email protected]", "bash", "run_on_scc.sh"],
capture_output=True,
text=True)
return "Computing..."
# Function to update the summary textbox
def update_summary(datasets, machines):
# datasets and machines are lists, not dictionaries
summary_text = f"Selected Datasets:\n{', '.join(datasets) if datasets else 'None'}\n\n"
summary_text += f"Selected Machines:\n{', '.join(machines) if machines else 'None'}"
return summary_text
# Gradio components
with gr.Blocks() as app:
gr.Markdown("# Cancer Analysis Tool")
# Tab 1: Dataset Selection
with gr.Tab("Dataset"):
datasets = gr.CheckboxGroup(
["Binary Colon", "Binary Lung", "Binary Prostate"],
label="Select Datasets:"
)
# Tab 2: Machine Selection
with gr.Tab("Machines"):
machines = gr.CheckboxGroup(
["Binary SVM", "Binary KNN", "Binary Deepnet"],
label="Select Machines:"
)
# Tab 3: Summary and Analysis
with gr.Tab("Analysis"):
summary = gr.Textbox(label="Summary of Selections", interactive=False, lines=5)
run_button = gr.Button("Run Analysis")
result = gr.Textbox(label="Result", interactive=False)
# Trigger analysis
run_button.click(
run_analysis,
inputs=[datasets, machines],
outputs=result
)
# Update summary when selections change
datasets.change(update_summary, [datasets, machines], summary)
machines.change(update_summary, [datasets, machines], summary)
# Launch the Gradio interface
app.launch(share=True)