Update app.py
Browse files
app.py
CHANGED
|
@@ -24,6 +24,15 @@ def validation(username : str, password : str):
|
|
| 24 |
password_db = row["Contraseña"].to_numpy().tolist()[0]
|
| 25 |
return password == password_db
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
with gr.Blocks(title="Clasificación") as AIModel:
|
| 28 |
with gr.Row():
|
| 29 |
with gr.Column():
|
|
@@ -31,37 +40,56 @@ with gr.Blocks(title="Clasificación") as AIModel:
|
|
| 31 |
segment_file = gr.File(file_count="single", file_types=[".nii.gz", ".nii"], type="filepath", label="Segmento")
|
| 32 |
dropdown_navigator = gr.Dropdown(value="eje X", choices=["eje X", "eje Y", "eje Z"], filterable=True, type="value", label="Eje")
|
| 33 |
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
| 35 |
brain_volume_data = nib.load(image).get_fdata()
|
| 36 |
if axis == "eje X":
|
| 37 |
-
|
|
|
|
|
|
|
| 38 |
image = Image.fromarray(slice)
|
| 39 |
image = image.rotate(90)
|
| 40 |
-
return image
|
| 41 |
elif axis == "eje Y":
|
| 42 |
-
|
|
|
|
|
|
|
| 43 |
image = Image.fromarray(slice)
|
| 44 |
image = image.rotate(90)
|
| 45 |
-
return image
|
| 46 |
else:
|
| 47 |
-
|
|
|
|
|
|
|
| 48 |
image = Image.fromarray(slice)
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
return
|
| 55 |
if axis == "eje X":
|
| 56 |
-
|
|
|
|
|
|
|
| 57 |
elif axis == "eje Y":
|
| 58 |
-
|
|
|
|
|
|
|
| 59 |
else:
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
with gr.Column():
|
| 66 |
label_output = gr.Label(label="Resultado")
|
| 67 |
comment_output = gr.Textbox(label="Observación", type="text", interactive=True)
|
|
@@ -69,135 +97,208 @@ with gr.Blocks(title="Clasificación") as AIModel:
|
|
| 69 |
with gr.Column():
|
| 70 |
with gr.Row():
|
| 71 |
with gr.Column():
|
| 72 |
-
clear_button = gr.ClearButton(value="Borrar", components=[image_file, segment_file, label_output, comment_output])
|
| 73 |
with gr.Column():
|
| 74 |
submit_button = gr.Button(value="Enviar", variant="primary")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
with gr.Column():
|
| 76 |
-
flag_button = gr.Button(value="
|
| 77 |
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
new_prediction = {
|
| 88 |
-
"Imagen": image,
|
| 89 |
-
"Grado 1":grade1,
|
| 90 |
-
"Grado 2": grade2,
|
| 91 |
-
"Observacion": comment_output,
|
| 92 |
-
"Usuario ID": 1,
|
| 93 |
-
"Ultima actualizacion": datetime.utcnow(),
|
| 94 |
-
"Creado el": datetime.utcnow()
|
| 95 |
-
}
|
| 96 |
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
|
| 113 |
-
flag_button.click(fn=
|
| 114 |
-
submit_button.click(fn=
|
| 115 |
|
| 116 |
-
|
| 117 |
-
with gr.Blocks(title="Historial de diagnósticos") as ViewingHistory:
|
| 118 |
-
temp = pd.read_sql_table("Predicciones", "sqlite:///database_test.db")
|
| 119 |
-
gr.Dataframe(temp, type="pandas", wrap=True, interactive=False)
|
| 120 |
-
|
| 121 |
with gr.Blocks(title="Base de datos") as Database:
|
|
|
|
|
|
|
|
|
|
| 122 |
with gr.Row():
|
| 123 |
with gr.Column():
|
| 124 |
-
|
| 125 |
-
filterable=False, label="Tabla")
|
| 126 |
with gr.Column():
|
| 127 |
-
|
|
|
|
|
|
|
| 128 |
with gr.Row():
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
def
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
button.click(on_selected, dropdown, dataframe)
|
| 135 |
-
|
| 136 |
-
with gr.Blocks(title="Información de usuario", delete_cache=[60, 120]) as AdminInformation:
|
| 137 |
-
|
| 138 |
-
username : str = ""
|
| 139 |
-
first_names : str = ""
|
| 140 |
-
last_names : str = ""
|
| 141 |
-
email : str = ""
|
| 142 |
-
phone : int = 0
|
| 143 |
-
is_admin : bool = False
|
| 144 |
-
|
| 145 |
-
table = pd.read_sql_table(table_name="Usuarios", con="sqlite:///database_test.db")
|
| 146 |
-
row = table[table["ID"] == 1]
|
| 147 |
-
|
| 148 |
-
def make_interactive(input_first_names, input_username, input_last_names, input_email, input_phone):
|
| 149 |
return (
|
| 150 |
-
gr.
|
| 151 |
-
gr.
|
| 152 |
-
gr.Textbox(label="Apellidos", interactive=True, max_lines=1),
|
| 153 |
-
gr.Textbox(label="Correo electrónico", interactive=True, max_lines=1),
|
| 154 |
-
gr.Textbox(label="Número de teléfono", interactive=True, max_lines=1)
|
| 155 |
)
|
| 156 |
|
| 157 |
-
def
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
phone = row["Telefono"].to_numpy().tolist()[0]
|
| 179 |
-
is_admin = row["Es Administrador"].to_numpy().tolist()[0]
|
| 180 |
|
|
|
|
| 181 |
with gr.Row():
|
| 182 |
with gr.Column():
|
| 183 |
input_profile_image = gr.Image(interactive=False)
|
| 184 |
with gr.Column():
|
| 185 |
-
input_first_names = gr.Textbox(
|
| 186 |
-
input_username = gr.Textbox(
|
| 187 |
-
|
| 188 |
with gr.Column():
|
| 189 |
-
input_last_names = gr.Textbox(
|
| 190 |
-
input_email = gr.Textbox(
|
| 191 |
-
input_phone = gr.Textbox(
|
| 192 |
with gr.Row():
|
| 193 |
with gr.Row():
|
| 194 |
edit_button = gr.Button(value="Editar")
|
| 195 |
save_button = gr.Button(value="Guardar", variant="primary")
|
| 196 |
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 200 |
|
|
|
|
|
|
|
|
|
|
| 201 |
|
| 202 |
Demo = gr.TabbedInterface(
|
| 203 |
interface_list=[AIModel, ViewingHistory, Database, AdminInformation],
|
|
|
|
| 24 |
password_db = row["Contraseña"].to_numpy().tolist()[0]
|
| 25 |
return password == password_db
|
| 26 |
|
| 27 |
+
with gr.Blocks(title="Historial de diagnósticos") as ViewingHistory:
|
| 28 |
+
history_dataframe = gr.Dataframe(visible=False, type="pandas", wrap=True, interactive=False)
|
| 29 |
+
|
| 30 |
+
def update_dataframe(history_dataframe):
|
| 31 |
+
temp = pd.read_sql_table(table_name="Predicciones", con="sqlite:///database_test.db")
|
| 32 |
+
return gr.Dataframe(value=temp, visible=True, type="pandas", wrap=True, interactive=False)
|
| 33 |
+
|
| 34 |
+
ViewingHistory.load(fn=update_dataframe, inputs=[history_dataframe], outputs=[history_dataframe])
|
| 35 |
+
|
| 36 |
with gr.Blocks(title="Clasificación") as AIModel:
|
| 37 |
with gr.Row():
|
| 38 |
with gr.Column():
|
|
|
|
| 40 |
segment_file = gr.File(file_count="single", file_types=[".nii.gz", ".nii"], type="filepath", label="Segmento")
|
| 41 |
dropdown_navigator = gr.Dropdown(value="eje X", choices=["eje X", "eje Y", "eje Z"], filterable=True, type="value", label="Eje")
|
| 42 |
|
| 43 |
+
slider = gr.Slider(visible=False)
|
| 44 |
+
image_preview = gr.Image(visible=False)
|
| 45 |
+
|
| 46 |
+
def preview_image(axis, image):
|
| 47 |
brain_volume_data = nib.load(image).get_fdata()
|
| 48 |
if axis == "eje X":
|
| 49 |
+
middle_index = brain_volume_data.shape[0] // 2
|
| 50 |
+
max_index = brain_volume_data.shape[0] - 1
|
| 51 |
+
slice = brain_volume_data[middle_index, :, :]
|
| 52 |
image = Image.fromarray(slice)
|
| 53 |
image = image.rotate(90)
|
|
|
|
| 54 |
elif axis == "eje Y":
|
| 55 |
+
middle_index = brain_volume_data.shape[1] // 2
|
| 56 |
+
max_index = brain_volume_data.shape[1] - 1
|
| 57 |
+
slice = brain_volume_data[:, middle_index, :]
|
| 58 |
image = Image.fromarray(slice)
|
| 59 |
image = image.rotate(90)
|
|
|
|
| 60 |
else:
|
| 61 |
+
middle_index = brain_volume_data.shape[2] // 2
|
| 62 |
+
max_index = brain_volume_data.shape[2] - 1
|
| 63 |
+
slice = brain_volume_data[:, :, middle_index]
|
| 64 |
image = Image.fromarray(slice)
|
| 65 |
+
image = image.rotate(90)
|
| 66 |
+
|
| 67 |
+
return (
|
| 68 |
+
gr.Slider(value=middle_index, minimum=0, maximum=max_index, visible=True),
|
| 69 |
+
gr.Image(value=image, label="Previsualización", type="pil", visible=True, interactive=False, show_download_button=True)
|
| 70 |
+
)
|
| 71 |
|
| 72 |
+
def slicing_image(axis, image, index):
|
| 73 |
+
brain_volume_data = nib.load(image).get_fdata()
|
| 74 |
+
|
|
|
|
| 75 |
if axis == "eje X":
|
| 76 |
+
slice = brain_volume_data[index, :, :]
|
| 77 |
+
image = Image.fromarray(slice)
|
| 78 |
+
image = image.rotate(90)
|
| 79 |
elif axis == "eje Y":
|
| 80 |
+
slice = brain_volume_data[:, index, :]
|
| 81 |
+
image = Image.fromarray(slice)
|
| 82 |
+
image = image.rotate(90)
|
| 83 |
else:
|
| 84 |
+
slice = brain_volume_data[:, :, index]
|
| 85 |
+
image = Image.fromarray(slice)
|
| 86 |
+
|
| 87 |
+
return (
|
| 88 |
+
gr.Image(value=image, label="Previsualización", type="pil", visible=True, interactive=False, show_download_button=True)
|
| 89 |
+
)
|
| 90 |
+
dropdown_navigator.change(fn=preview_image, inputs=[dropdown_navigator, image_file], outputs=[slider, image_preview])
|
| 91 |
+
image_file.upload(fn=preview_image, inputs=[dropdown_navigator, image_file], outputs=[slider, image_preview])
|
| 92 |
+
slider.change(fn=slicing_image, inputs=[dropdown_navigator, image_file, slider], outputs=[image_preview])
|
| 93 |
with gr.Column():
|
| 94 |
label_output = gr.Label(label="Resultado")
|
| 95 |
comment_output = gr.Textbox(label="Observación", type="text", interactive=True)
|
|
|
|
| 97 |
with gr.Column():
|
| 98 |
with gr.Row():
|
| 99 |
with gr.Column():
|
| 100 |
+
clear_button = gr.ClearButton(value="Borrar", components=[image_file, segment_file, label_output, comment_output, dropdown_navigator])
|
| 101 |
with gr.Column():
|
| 102 |
submit_button = gr.Button(value="Enviar", variant="primary")
|
| 103 |
+
|
| 104 |
+
def clear_image_preview(image_preview, slider):
|
| 105 |
+
return (gr.Image(visible=False), gr.Slider(visible=False))
|
| 106 |
+
|
| 107 |
+
clear_button.click(fn=clear_image_preview, inputs=[image_preview, slider], outputs=[image_preview, slider])
|
| 108 |
with gr.Column():
|
| 109 |
+
flag_button = gr.Button(value="Guardar")
|
| 110 |
|
| 111 |
+
def save_prediction(image, label_output, comment_output):
|
| 112 |
+
grade1 = list(label_output.values())[0]
|
| 113 |
+
grade2 = list(label_output.values())[1]
|
| 114 |
+
engine = sqlalchemy.create_engine("sqlite:///database_test.db", echo=False)
|
| 115 |
+
Session = sessionmaker(bind=engine)
|
| 116 |
+
session = Session()
|
| 117 |
+
metadata = sqlalchemy.MetaData()
|
| 118 |
+
predictions_table = sqlalchemy.Table("Predicciones", metadata, autoload_with=engine)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
|
| 120 |
+
new_prediction = {
|
| 121 |
+
"Imagen": image,
|
| 122 |
+
"Grado 1":grade1,
|
| 123 |
+
"Grado 2": grade2,
|
| 124 |
+
"Observacion": comment_output,
|
| 125 |
+
"Usuario ID": 1,
|
| 126 |
+
"Ultima actualizacion": datetime.utcnow(),
|
| 127 |
+
"Creado el": datetime.utcnow()
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
stmt = predictions_table.insert().values(**new_prediction)
|
| 131 |
+
session.execute(stmt)
|
| 132 |
+
session.commit()
|
| 133 |
+
return gr.Info("Se ha guardado exitosamente")
|
| 134 |
|
| 135 |
+
def classify_image(image, segment):
|
| 136 |
+
features3D = extractor3D.execute(imageFilepath=image, maskFilepath=segment)
|
| 137 |
+
dict = {}
|
| 138 |
+
for key, value in zip(features3D.keys(), features3D.values()):
|
| 139 |
+
if isinstance(value, np.ndarray):
|
| 140 |
+
dict[key] = [value.tolist()]
|
| 141 |
+
else:
|
| 142 |
+
dict[key] = [value]
|
| 143 |
+
temp = pd.DataFrame(dict).select_dtypes(exclude=["object"]).to_numpy()
|
| 144 |
+
prediction = loaded_model.predict_proba(temp).tolist()[0]
|
| 145 |
+
return {"Grado 1": prediction[0], "Grado 2": prediction[1]}
|
| 146 |
|
| 147 |
+
flag_button.click(fn=save_prediction, inputs=[image_file, label_output, comment_output]).success(update_dataframe, history_dataframe, history_dataframe)
|
| 148 |
+
submit_button.click(fn=classify_image, inputs=[image_file, segment_file], outputs=[label_output])
|
| 149 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
with gr.Blocks(title="Base de datos") as Database:
|
| 151 |
+
with gr.Row():
|
| 152 |
+
table_dropdown = gr.Dropdown(value="Usuarios", choices=["Usuarios", "Predicciones"],
|
| 153 |
+
filterable=True, label="Tabla")
|
| 154 |
with gr.Row():
|
| 155 |
with gr.Column():
|
| 156 |
+
action_dropdown = gr.Dropdown(choices=["Eliminar", "Descargar"], filterable=True, label="Acciones")
|
|
|
|
| 157 |
with gr.Column():
|
| 158 |
+
id_dropdown = gr.Dropdown(visible=False, filterable=True, label="Identificador (ID)")
|
| 159 |
+
with gr.Column():
|
| 160 |
+
action_button = gr.Button(visible=False)
|
| 161 |
with gr.Row():
|
| 162 |
+
database_dataframe = gr.Dataframe(visible=False, type="pandas", wrap=True, interactive=False)
|
| 163 |
+
|
| 164 |
+
def on_table_dropdown_change(table_dropdown, database_dataframe, id_dropdown):
|
| 165 |
+
temp = pd.read_sql_table(table_dropdown, "sqlite:///database_test.db")
|
| 166 |
+
ids = temp["ID"].values.flatten().tolist()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 167 |
return (
|
| 168 |
+
gr.Dataframe(value=temp, visible=True, type="pandas", wrap=True, interactive=False),
|
| 169 |
+
gr.Dropdown(choices=ids, visible=True, filterable=True, label="Identificador (ID)"),
|
|
|
|
|
|
|
|
|
|
| 170 |
)
|
| 171 |
|
| 172 |
+
def on_database_load(table_dropdown, database_dataframe):
|
| 173 |
+
temp = pd.read_sql_table(table_dropdown, "sqlite:///database_test.db")
|
| 174 |
+
return gr.Dataframe(value=temp, visible=True, type="pandas", wrap=True, interactive=False)
|
| 175 |
+
|
| 176 |
+
def on_action_dropdown_change(action_dropdown):
|
| 177 |
+
return gr.Button(value=action_dropdown, visible=True, variant="primary")
|
| 178 |
+
|
| 179 |
+
def on_action_button_click(table_dropdown, action_dropdown, id_dropdown, database_dataframe):
|
| 180 |
+
if action_dropdown == "Eliminar":
|
| 181 |
+
engine = sqlalchemy.create_engine("sqlite:///database_test.db", echo=False)
|
| 182 |
+
Session = sessionmaker(bind=engine)
|
| 183 |
+
session = Session()
|
| 184 |
+
metadata = sqlalchemy.MetaData()
|
| 185 |
+
table = sqlalchemy.Table(table_dropdown, metadata, autoload_with=engine)
|
| 186 |
+
stmt = sqlalchemy.delete(table).where(table.c.ID == id_dropdown)
|
| 187 |
+
session.execute(stmt)
|
| 188 |
+
session.commit()
|
| 189 |
+
return gr.Info(f"Se ha eliminado el registro #{id_dropdown}")
|
| 190 |
+
elif action_dropdown == "Descargar":
|
| 191 |
+
if table_dropdown == "Predicciones":
|
| 192 |
+
file_path = database_dataframe["Imagen"].to_numpy().tolist()[0]
|
| 193 |
+
print(file_path)
|
| 194 |
+
return gr.DownloadButton(value=file_path)
|
| 195 |
+
#return gr.Info(f"Se ha descargado el registro #{id_dropdown}")
|
| 196 |
|
| 197 |
+
table_dropdown.change(fn=on_table_dropdown_change, inputs=[table_dropdown, database_dataframe, id_dropdown], outputs=[database_dataframe, id_dropdown])
|
| 198 |
+
Database.load(fn=on_database_load, inputs=[table_dropdown, database_dataframe], outputs=[database_dataframe]).success(fn=on_table_dropdown_change, inputs=[table_dropdown, database_dataframe, id_dropdown], outputs=[database_dataframe, id_dropdown])
|
| 199 |
+
action_dropdown.change(fn=on_action_dropdown_change, inputs=[action_dropdown], outputs=[action_button])
|
| 200 |
+
action_button.click(fn=on_action_button_click, inputs=[table_dropdown, action_dropdown, id_dropdown, database_dataframe], outputs=[action_dropdown])
|
| 201 |
+
|
|
|
|
|
|
|
| 202 |
|
| 203 |
+
with gr.Blocks(title="Información de usuario") as AdminInformation:
|
| 204 |
with gr.Row():
|
| 205 |
with gr.Column():
|
| 206 |
input_profile_image = gr.Image(interactive=False)
|
| 207 |
with gr.Column():
|
| 208 |
+
input_first_names = gr.Textbox(label="Nombres", interactive=False, type="text", max_lines=1)
|
| 209 |
+
input_username = gr.Textbox(label="Usuario", interactive=False, type="text", max_lines=1)
|
| 210 |
+
input_is_admin = gr.Textbox(label="Rol", interactive=False, type="text", max_lines=1)
|
| 211 |
with gr.Column():
|
| 212 |
+
input_last_names = gr.Textbox(label="Apellidos", interactive=False, type="text", max_lines=1)
|
| 213 |
+
input_email = gr.Textbox(label="Correo electrónico", interactive=False, type="email", max_lines=1)
|
| 214 |
+
input_phone = gr.Textbox(label="Número de teléfono", interactive=False, type="text", max_lines=1)
|
| 215 |
with gr.Row():
|
| 216 |
with gr.Row():
|
| 217 |
edit_button = gr.Button(value="Editar")
|
| 218 |
save_button = gr.Button(value="Guardar", variant="primary")
|
| 219 |
|
| 220 |
+
def FillFields(input_username, input_first_names, input_last_names, input_email, input_phone, input_is_admin):
|
| 221 |
+
|
| 222 |
+
table = pd.read_sql_table(table_name="Usuarios", con="sqlite:///database_test.db")
|
| 223 |
+
row = table[table["ID"] == 1]
|
| 224 |
+
|
| 225 |
+
if not row.empty:
|
| 226 |
+
username_db = row["Usuario"].to_numpy().tolist()[0]
|
| 227 |
+
first_names_db = row["Nombres"].to_numpy().tolist()[0]
|
| 228 |
+
last_names_db = row["Apellidos"].to_numpy().tolist()[0]
|
| 229 |
+
email_db = row["Correo electronico"].to_numpy().tolist()[0]
|
| 230 |
+
phone_db = row["Telefono"].to_numpy().tolist()[0]
|
| 231 |
+
is_admin_db = row["Es Administrador"].to_numpy().tolist()[0]
|
| 232 |
+
else:
|
| 233 |
+
username_db = ""
|
| 234 |
+
first_names_db = ""
|
| 235 |
+
last_names_db = ""
|
| 236 |
+
email_db = ""
|
| 237 |
+
phone_db = ""
|
| 238 |
+
is_admin_db = False
|
| 239 |
+
|
| 240 |
+
return (
|
| 241 |
+
gr.Textbox(value=username_db, label="Usuario", interactive=False, max_lines=1),
|
| 242 |
+
gr.Textbox(value=first_names_db, label="Nombres", interactive=False, max_lines=1),
|
| 243 |
+
gr.Textbox(value=last_names_db, label="Apellidos", interactive=False, max_lines=1),
|
| 244 |
+
gr.Textbox(value=email_db, label="Correo electrónico", interactive=False, max_lines=1),
|
| 245 |
+
gr.Textbox(value=phone_db, label="Número de teléfono", interactive=False, max_lines=1),
|
| 246 |
+
gr.Textbox(value="Administrador" if is_admin_db else "Doctor", label="Rol", interactive=False, type="text", max_lines=1)
|
| 247 |
+
)
|
| 248 |
+
|
| 249 |
+
def make_editable(edit_button, input_username, input_first_names, input_last_names, input_email, input_phone):
|
| 250 |
+
|
| 251 |
+
if edit_button == "Editar":
|
| 252 |
+
return (
|
| 253 |
+
gr.Button(value="Cancelar"),
|
| 254 |
+
gr.Textbox(value=input_username, interactive=True),
|
| 255 |
+
gr.Textbox(value=input_first_names, interactive=True),
|
| 256 |
+
gr.Textbox(value=input_last_names, interactive=True),
|
| 257 |
+
gr.Textbox(value=input_email, interactive=True),
|
| 258 |
+
gr.Textbox(value=input_phone, interactive=True),
|
| 259 |
+
)
|
| 260 |
+
else:
|
| 261 |
+
return (
|
| 262 |
+
gr.Button(value="Editar"),
|
| 263 |
+
gr.Textbox(value=input_username, interactive=True),
|
| 264 |
+
gr.Textbox(value=input_first_names, interactive=True),
|
| 265 |
+
gr.Textbox(value=input_last_names, interactive=True),
|
| 266 |
+
gr.Textbox(value=input_email, interactive=True),
|
| 267 |
+
gr.Textbox(value=input_phone, interactive=True),
|
| 268 |
+
)
|
| 269 |
+
|
| 270 |
+
def save_values(input_username, input_first_names, input_last_names, input_email, input_phone):
|
| 271 |
+
#connection = sqlite3.connect("database_test.db")
|
| 272 |
+
#cursor = connection.cursor()
|
| 273 |
+
#data = cursor.execute(f'''UPDATE Usuarios SET Nombres = '{input_first_names}', Usuario = '{input_username}', Apellidos = '{input_last_names}', "Correo electronico" = '{input_email}', Telefono = '{input_phone}' WHERE ID==1;''')
|
| 274 |
+
#connection.commit()
|
| 275 |
+
#connection.close()
|
| 276 |
+
engine = sqlalchemy.create_engine("sqlite:///database_test.db", echo=False)
|
| 277 |
+
Session = sessionmaker(bind=engine)
|
| 278 |
+
session = Session()
|
| 279 |
+
metadata = sqlalchemy.MetaData()
|
| 280 |
+
table = sqlalchemy.Table("Usuarios", metadata, autoload_with=engine)
|
| 281 |
+
new_user = {
|
| 282 |
+
"Usuario": input_username,
|
| 283 |
+
"Nombres": input_first_names,
|
| 284 |
+
"Apellidos": input_last_names,
|
| 285 |
+
"Correo electronico": input_email,
|
| 286 |
+
"Telefono": input_phone
|
| 287 |
+
}
|
| 288 |
+
stmt = sqlalchemy.update(table).where(table.c.ID == 1).values(**new_user)
|
| 289 |
+
session.execute(stmt)
|
| 290 |
+
session.commit()
|
| 291 |
+
return (
|
| 292 |
+
gr.Textbox(value=input_username, interactive=False),
|
| 293 |
+
gr.Textbox(value=input_first_names, interactive=False),
|
| 294 |
+
gr.Textbox(value=input_last_names, interactive=False),
|
| 295 |
+
gr.Textbox(value=input_email, interactive=False),
|
| 296 |
+
gr.Textbox(value=input_phone, interactive=False),
|
| 297 |
+
)
|
| 298 |
|
| 299 |
+
AdminInformation.load(fn=FillFields, inputs=[input_username, input_first_names, input_last_names, input_email, input_phone, input_is_admin], outputs=[input_username, input_first_names, input_last_names, input_email, input_phone, input_is_admin])
|
| 300 |
+
edit_button.click(fn=make_editable, inputs=[edit_button, input_username, input_first_names, input_last_names, input_email, input_phone], outputs=[edit_button, input_username, input_first_names, input_last_names, input_email, input_phone])
|
| 301 |
+
save_button.click(fn=save_values, inputs=[input_username, input_first_names, input_last_names, input_email, input_phone], outputs=[input_username, input_first_names, input_last_names, input_email, input_phone])
|
| 302 |
|
| 303 |
Demo = gr.TabbedInterface(
|
| 304 |
interface_list=[AIModel, ViewingHistory, Database, AdminInformation],
|