import gradio as gr import random import time fp = open("/deep2/u/eprakash/MedSegDiff/data/ISIC/ISBI2016_ISIC_Part3B_Training_GroundTruth.csv") image_ids = [] for line in fp: image_ids.append(line.split(",")[0].split("_")[1]) image_ids = image_ids[:700] rankings = [] def load_next(rank, img_1, img_2, img_3, img_4, img_5, example, ids=image_ids): if example == len(image_ids): return [None, None, None, None, None, None, None] else: rankings.append(str(image_ids[int(example)-1]) + "," + rank) r_fp = open("ranks/isic_ranks_" + str(int(example) - 1) +".csv", "w") for r in rankings: r_fp.write(r + "\n") r_fp.close() example += 1 rank = "" img_1 = gr.Image(label="Sample #1", value="/deep2/u/eprakash/Diffusion-based-Segmentation/isic_synthetic_data/" + str(image_ids[int(example)-1]) + "_synthetic_0.jpg", interactive=False) img_2 = gr.Image(label="Sample #2", value="/deep2/u/eprakash/Diffusion-based-Segmentation/isic_synthetic_data/" + str(image_ids[int(example)-1]) + "_synthetic_1.jpg", interactive=False) img_3 = gr.Image(label="Sample #3", value="/deep2/u/eprakash/Diffusion-based-Segmentation/isic_synthetic_data/" + str(image_ids[int(example)-1]) + "_synthetic_2.jpg", interactive=False) img_4 = gr.Image(label="Sample #4", value="/deep2/u/eprakash/Diffusion-based-Segmentation/isic_synthetic_data/" + str(image_ids[int(example)-1]) + "_synthetic_3.jpg", interactive=False) img_5 = gr.Image(label="Sample #5", value="/deep2/u/eprakash/Diffusion-based-Segmentation/isic_synthetic_data/" + str(image_ids[int(example)-1]) + "_synthetic_4.jpg", interactive=False) return [rank, img_1, img_2, img_3, img_4, img_5, example] with gr.Blocks() as demo: example = gr.Number(label="Example #", value=1, interactive=False) rank = gr.Textbox(label="Rankings (Best to worst, comma-separated, no spaces)") with gr.Row(): img_1 = gr.Image(label="Sample #1", value="/deep2/u/eprakash/Diffusion-based-Segmentation/isic_synthetic_data/" + str(image_ids[0]) + "_synthetic_0.jpg", interactive=False) img_2 = gr.Image(label="Sample #2", value="/deep2/u/eprakash/Diffusion-based-Segmentation/isic_synthetic_data/" + str(image_ids[0]) + "_synthetic_1.jpg", interactive=False) img_3 = gr.Image(label="Sample #3", value="/deep2/u/eprakash/Diffusion-based-Segmentation/isic_synthetic_data/" + str(image_ids[0]) + "_synthetic_2.jpg", interactive=False) img_4 = gr.Image(label="Sample #4", value="/deep2/u/eprakash/Diffusion-based-Segmentation/isic_synthetic_data/" + str(image_ids[0]) + "_synthetic_3.jpg", interactive=False) img_5 = gr.Image(label="Sample #5", value="/deep2/u/eprakash/Diffusion-based-Segmentation/isic_synthetic_data/" + str(image_ids[0]) + "_synthetic_4.jpg", interactive=False) next_btn = gr.Button(value="Next") next_btn.click(fn=load_next, inputs=[rank, img_1, img_2, img_3, img_4, img_5, example], outputs=[rank, img_1, img_2, img_3, img_4, img_5, example], queue=False) demo.queue() demo.launch(share=True) fp.close()