Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
-
import sys
|
| 2 |
-
from datetime import date
|
| 3 |
import gradio as gr
|
|
|
|
| 4 |
import pandas as pd
|
| 5 |
from pickle import load
|
|
|
|
| 6 |
from radiomics import featureextractor
|
| 7 |
|
| 8 |
extractor3D = featureextractor.RadiomicsFeatureExtractor("3DParams.yaml")
|
|
@@ -23,43 +23,40 @@ class TextStream:
|
|
| 23 |
|
| 24 |
def image_classifier(image, segment):
|
| 25 |
features3D = extractor3D.execute(imageFilepath=image, maskFilepath=segment)
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
print(*sortedValues, sep="\n")
|
| 34 |
-
sys.stdout = original_stdout
|
| 35 |
-
sortedValues = text_stream.data[4:7] + text_stream.data[15:17] + text_stream.data[22:]
|
| 36 |
-
dataframe = pd.DataFrame(
|
| 37 |
-
data=sortedValues,
|
| 38 |
-
)
|
| 39 |
-
dataframe = dataframe.transpose()
|
| 40 |
prediction = loaded_model.predict_proba(dataframe).tolist()[0]
|
| 41 |
return {"Grade 1": prediction[0], "Grade 2": prediction[1]}
|
| 42 |
|
| 43 |
def logging(image, label_output):
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
"
|
| 49 |
-
"
|
| 50 |
-
"
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
print(dataframe)
|
| 54 |
|
| 55 |
# Logger = gr.SimpleCSVLogger()
|
| 56 |
|
| 57 |
with gr.Blocks(title="Historial de diagnósticos") as ViewingHistory:
|
|
|
|
| 58 |
gr.Dataframe(
|
|
|
|
| 59 |
headers=["Imagen", "Grado 1", "Grado 2", "Observación", "Fecha", "Acción"],
|
| 60 |
datatype=["str", "number", "number", "str", "date", "markdown"],
|
| 61 |
-
row_count=(3, "dynamic"),
|
| 62 |
-
col_count=(6, "dynamic"),
|
| 63 |
type="pandas",
|
| 64 |
wrap=True
|
| 65 |
)
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import numpy as np
|
| 3 |
import pandas as pd
|
| 4 |
from pickle import load
|
| 5 |
+
from datetime import date
|
| 6 |
from radiomics import featureextractor
|
| 7 |
|
| 8 |
extractor3D = featureextractor.RadiomicsFeatureExtractor("3DParams.yaml")
|
|
|
|
| 23 |
|
| 24 |
def image_classifier(image, segment):
|
| 25 |
features3D = extractor3D.execute(imageFilepath=image, maskFilepath=segment)
|
| 26 |
+
dict = {}
|
| 27 |
+
for key, value in zip(features3D.keys(), features3D.values()):
|
| 28 |
+
if isinstance(value, np.ndarray):
|
| 29 |
+
dict[key] = [value.tolist()]
|
| 30 |
+
else:
|
| 31 |
+
dict[key] = [value]
|
| 32 |
+
dataframe = pd.DataFrame(dict).select_dtypes(exclude=["object"]).to_numpy()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
prediction = loaded_model.predict_proba(dataframe).tolist()[0]
|
| 34 |
return {"Grade 1": prediction[0], "Grade 2": prediction[1]}
|
| 35 |
|
| 36 |
def logging(image, label_output):
|
| 37 |
+
grade1 = list(label_output.values())[0]
|
| 38 |
+
grade2 = list(label_output.values())[1]
|
| 39 |
+
now = date.today()
|
| 40 |
+
dictionary = {
|
| 41 |
+
"Imagen": [image],
|
| 42 |
+
"Grado 1": [grade1],
|
| 43 |
+
"Grado 2": [grade2],
|
| 44 |
+
"Observación": [""],
|
| 45 |
+
"Fecha": [now.strftime("%d/%m/%Y")],
|
| 46 |
+
"Acción": [f"\"\"\"[Descargar]({image})\"\"\""]
|
| 47 |
+
}
|
| 48 |
+
dataframe = pd.DataFrame(data=dictionary)
|
| 49 |
+
dataframe.to_csv(path_or_buf="log.csv", sep=";", mode="a", index=False)
|
| 50 |
print(dataframe)
|
| 51 |
|
| 52 |
# Logger = gr.SimpleCSVLogger()
|
| 53 |
|
| 54 |
with gr.Blocks(title="Historial de diagnósticos") as ViewingHistory:
|
| 55 |
+
dataframe = pd.read_csv(filepath_or_buffer="log.csv", sep=";")
|
| 56 |
gr.Dataframe(
|
| 57 |
+
value=dataframe,
|
| 58 |
headers=["Imagen", "Grado 1", "Grado 2", "Observación", "Fecha", "Acción"],
|
| 59 |
datatype=["str", "number", "number", "str", "date", "markdown"],
|
|
|
|
|
|
|
| 60 |
type="pandas",
|
| 61 |
wrap=True
|
| 62 |
)
|