import gradio as gr import numpy as np import pandas as pd #Assembling and Processing Data def prepData(engSL, engHL, hindiBSL, hindiBHL, spanAbSL, spanAbHL, spanBSL, spanBHL, frenchAbSL, frenchAbHL, frenchBSL, frenchBHL, bmSL, bmHL, econSL, econHL, psychSL, psychHL, chemSL, chemHL, bioSL, bioHL, phySL, phyHL, csSL, csHL, maaSL, maaHL, maiSL, maiHL, vaSL, vaHL, essSL, essHL): data = [engSL, engHL, hindiBSL, hindiBHL, spanAbSL, spanAbHL, spanBSL, spanBHL, frenchAbSL, frenchAbHL, frenchBSL, frenchBHL, bmSL, bmHL, econSL, econHL, psychSL, psychHL, chemSL, chemHL, bioSL, bioHL, phySL, phyHL, csSL, csHL, maaSL, maaHL, maiSL, maiHL, vaSL, vaHL, essSL, essHL] # Location for assembling all subjects data subsData = [] subs = "engSL engHL hindiBSL hindiBHL spanAbSL spanAbHL spanBSL spanBHL frenchAbSL frenchAbHL frenchBSL frenchBHL bmSL bmHL econSL econHL psychSL psychHL chemSL chemHL bioSL bioHL phySL phyHL csSL csHL maaSL maaHL maiSL maiHL vaSL vaHL essSL essHL" subs = subs.split() for i in range(len(subs)): subsData.append([subs[i]]) # Counters k = -1 count = 0 for i in range(len(data)): # Inside each subject k = k + 1 lst = data[i].split() for j in lst: subsData[k].append(j) if len(lst) == 0: subsData.remove(subsData[k]) k = k - 1 # Processing Data compensations = [] for sub1 in range(k): for sub2 in range(sub1 + 1, k + 1): compensations.append([subsData[sub1][0] + "/" + subsData[sub2][0]]) cmn_lst = [] for i in range(1, len(subsData[sub1])): for j in range(1, len(subsData[sub2])): if subsData[sub1][i] == subsData[sub2][j]: cmn_lst.append(subsData[sub2][j]) compensations[count].append(len(cmn_lst)) cmn_lst = ' '.join(cmn_lst) compensations[count].append(cmn_lst) count = count + 1 for i in range(len(compensations)): for j in range(len(compensations[0])): if compensations[i][j] == 0: compensations[i][j + 1] = "NONE" return pd.DataFrame(compensations, columns=["Parallel Subjects", "No. of Compensations", "Compensations"]) def sortData(btnVal, compensation): compensations = compensation.values.tolist() if btnVal == "All": return compensation if btnVal == "Max 3": return [row for row in compensations if row[1] <= 3] if btnVal == "Max 2": return [row for row in compensations if row[1] <= 2] if btnVal == "Max 1": return [row for row in compensations if row[1] <= 1] if btnVal == "No Compensations": return [row for row in compensations if row[1] == 0] interface = gr.Interface(fn=prepData, inputs=[ *[gr.Textbox(placeholder="Enter student list here", label=f"Student List for {subject}") for subject in ["ENGLISH SL", "ENGLISH HL", "HINDI B SL", "HINDI B HL", "SPANISH AB INITIO SL", "SPANISH AB INITIO HL", "SPANISH B SL", "SPANISH B HL", "FRENCH AB INITIO SL", "FRENCH AB INITIO HL", "FRENCH B SL", "FRENCH B HL", "BM SL", "BM HL", "ECON SL", "ECON HL", "PSYCH SL", "PSYCH HL", "CHEM SL", "CHEM HL", "BIO SL", "BIO HL", "PHY SL", "PHY HL", "CS SL", "CS HL", "MAA SL", "MAA HL", "MAI SL", "MAI HL", "VA SL", "VA HL", "ESS SL", "ESS HL"]], *[gr.Textbox(placeholder="Enter student list here", label=f"Student List for {subject}") for subject in ["VA SL", "VA HL", "ESS SL", "ESS HL"]]], outputs=gr.Dataframe(headers=["Parallel Subjects", "No. of Compensations", "Compensations"])) interface.launch()