Update app.py
Browse files1234567814 unmodified lines23242526272829303132333435363738394041424344454647484950515253545556575859606162636465import sysfrom datetime import dateimport gradio as grimport pandas as pdfrom pickle import loadfrom radiomics import featureextractorextractor3D = featureextractor.RadiomicsFeatureExtractor("3DParams.yaml")14 unmodified linesdef image_classifier(image, segment):features3D = extractor3D.execute(imageFilepath=image, maskFilepath=segment)keys = [key for key in features3D.keys()]values = [value for value in features3D.values()]sortedLists = sorted(list(zip(keys, values)), key=lambda x: x[0])sortedKeys, sortedValues = zip(*sortedLists)original_stdout = sys.stdouttext_stream = TextStream()sys.stdout = text_streamprint(*sortedValues, sep="\n")sys.stdout = original_stdoutsortedValues = text_stream.data[4:7] + text_stream.data[15:17] + text_stream.data[22:]dataframe = pd.DataFrame(data=sortedValues,)dataframe = dataframe.transpose()prediction = loaded_model.predict_proba(dataframe).tolist()[0]return {"Grade 1": prediction[0], "Grade 2": prediction[1]}def logging(image, label_output):dataframe = pd.DataFrame(data={"Imagen": image,"Grado 1": label_output.values()[0],"Grado 2": label_output.values()[1],"Observación": "","Fecha": date.today(),"Acción": f"[Descarga]({image})"})dataframe.to_csv(path_or_buf="flagged/log.csv", sep=";")print(dataframe)# Logger = gr.SimpleCSVLogger()with gr.Blocks(title="Historial de diagnósticos") as ViewingHistory:gr.Dataframe(headers=["Imagen", "Grado 1", "Grado 2", "Observación", "Fecha", "Acción"],datatype=["str", "number", "number", "str", "date", "markdown"],row_count=(3, "dynamic"),col_count=(6, "dynamic"),type="pandas",wrap=True)1234567814 unmodified lines23242526272829303132333435363738394041424344454647484950515253545556575859606162import gradio as grimport numpy as npimport pandas as pdfrom pickle import loadfrom datetime import datefrom radiomics import featureextractorextractor3D = featureextractor.RadiomicsFeatureExtractor("3DParams.yaml")14 unmodified linesdef image_classifier(image, segment):features3D = extractor3D.execute(imageFilepath=image, maskFilepath=segment)dict = {}for key, value in zip(features3D.keys(), features3D.values()):if isinstance(value, np.ndarray):dict[key] = [value.tolist()]else:dict[key] = [value]dataframe = pd.DataFrame(dict).select_dtypes(exclude=["object"]).to_numpy()prediction = loaded_model.predict_proba(dataframe).tolist()[0]return {"Grade 1": prediction[0], "Grade 2": prediction[1]}def logging(image, label_output):grade1 = list(label_output.values())[0]grade2 = list(label_output.values())[1]now = date.today()dictionary = {"Imagen": [image],"Grado 1": [grade1],"Grado 2": [grade2],"Observación": [""],"Fecha": [now.strftime("%d/%m/%Y")],"Acción": [f"\"\"\"[Descargar]({image})\"\"\""]}dataframe = pd.DataFrame(data=dictionary)dataframe.to_csv(path_or_buf="log.csv", sep=";", mode="a", index=False)print(dataframe)# Logger = gr.SimpleCSVLogger()with gr.Blocks(title="Historial de diagnósticos") as ViewingHistory:dataframe = pd.read_csv(filepath_or_buffer="log.csv", sep=";")gr.Dataframe(value=dataframe,headers=["Imagen", "Grado 1", "Grado 2", "Observación", "Fecha", "Acción"],datatype=["str", "number", "number", "str", "date", "markdown"],type="pandas",wrap=True)
app.py+24-27