Update UI.py
Browse files
UI.py
CHANGED
@@ -2,112 +2,4 @@ import gradio as gr
|
|
2 |
import pandas as pd
|
3 |
import io
|
4 |
from PIL import Image
|
5 |
-
from
|
6 |
-
from bioprocess_model import BioprocessModel # Asegúrate de que BioprocessModel esté en su propio archivo
|
7 |
-
|
8 |
-
def create_interface(process_fn):
|
9 |
-
with gr.Blocks() as demo:
|
10 |
-
gr.Markdown("# Interfaz de Usuario para el Procesamiento de Datos de Bioproceso")
|
11 |
-
|
12 |
-
# Inputs de archivo y parámetros
|
13 |
-
file_input = gr.File(label="Subir archivo Excel con los datos", file_types=[".xls", ".xlsx"])
|
14 |
-
|
15 |
-
with gr.Row():
|
16 |
-
with gr.Column():
|
17 |
-
legend_position = gr.Radio(
|
18 |
-
choices=["upper left", "upper right", "lower left", "lower right", "best"],
|
19 |
-
label="Posición de la leyenda",
|
20 |
-
value="best"
|
21 |
-
)
|
22 |
-
show_legend = gr.Checkbox(label="Mostrar Leyenda", value=True)
|
23 |
-
|
24 |
-
with gr.Column():
|
25 |
-
params_positions = ["upper left", "upper right", "lower left", "lower right", "outside right"]
|
26 |
-
params_position = gr.Radio(
|
27 |
-
choices=params_positions,
|
28 |
-
label="Posición de los parámetros",
|
29 |
-
value="upper right"
|
30 |
-
)
|
31 |
-
show_params = gr.Checkbox(label="Mostrar Parámetros", value=True)
|
32 |
-
|
33 |
-
# Parámetros adicionales
|
34 |
-
model_type = gr.Radio(["logistic", "luedeking-piret"], label="Tipo de Modelo", value="logistic")
|
35 |
-
mode = gr.Radio(["independent", "average", "combinado"], label="Modo de Análisis", value="independent")
|
36 |
-
|
37 |
-
# Estilo gráfico
|
38 |
-
styles = ['white', 'dark', 'whitegrid', 'darkgrid', 'ticks']
|
39 |
-
style_dropdown = gr.Dropdown(choices=styles, label="Selecciona el estilo de gráfico", value='whitegrid')
|
40 |
-
|
41 |
-
line_color_picker = gr.ColorPicker(label="Color de la línea", value='#0000FF')
|
42 |
-
point_color_picker = gr.ColorPicker(label="Color de los puntos", value='#000000')
|
43 |
-
|
44 |
-
line_style_options = ['-', '--', '-.', ':']
|
45 |
-
line_style_dropdown = gr.Dropdown(choices=line_style_options, label="Estilo de línea", value='-')
|
46 |
-
|
47 |
-
marker_style_options = ['o', 's', '^', 'v', 'D', 'x', '+', '*']
|
48 |
-
marker_style_dropdown = gr.Dropdown(choices=marker_style_options, label="Estilo de punto", value='o')
|
49 |
-
|
50 |
-
# Botón de Procesar
|
51 |
-
process_button = gr.Button("Procesar")
|
52 |
-
|
53 |
-
# Salida
|
54 |
-
output_gallery = gr.Gallery(label="Gráfico Generado", columns=2, height='auto')
|
55 |
-
output_text = gr.Textbox(label="Análisis Generado", lines=10)
|
56 |
-
|
57 |
-
# Conectar el botón con la función de procesamiento
|
58 |
-
process_button.click(
|
59 |
-
fn=process_fn,
|
60 |
-
inputs=[file_input, legend_position, params_position, model_type, mode, style_dropdown,
|
61 |
-
line_color_picker, point_color_picker, line_style_dropdown, marker_style_dropdown,
|
62 |
-
show_legend, show_params],
|
63 |
-
outputs=[output_gallery, output_text]
|
64 |
-
)
|
65 |
-
|
66 |
-
return demo
|
67 |
-
|
68 |
-
def process_and_plot(file, legend_position, params_position, model_type, mode, style,
|
69 |
-
line_color, point_color, line_style, marker_style, show_legend, show_params):
|
70 |
-
# Leer el archivo Excel proporcionado
|
71 |
-
excel_data = pd.ExcelFile(file.name)
|
72 |
-
figures = []
|
73 |
-
model = BioprocessModel()
|
74 |
-
model.fit_model(model_type)
|
75 |
-
|
76 |
-
for sheet_name in excel_data.sheet_names:
|
77 |
-
df = pd.read_excel(excel_data, sheet_name=sheet_name)
|
78 |
-
model.process_data(df)
|
79 |
-
|
80 |
-
# Obtener los datos de tiempo, biomasa, sustrato y producto
|
81 |
-
time = model.time
|
82 |
-
biomass = model.dataxp[-1]
|
83 |
-
substrate = model.datasp[-1]
|
84 |
-
product = model.datapp[-1]
|
85 |
-
|
86 |
-
# Generar los gráficos
|
87 |
-
fig = model.plot_combined_results(time, biomass, substrate, product,
|
88 |
-
model.dataxp[-1], model.datasp[-1], model.datapp[-1],
|
89 |
-
model.datax_std[-1], model.datas_std[-1], model.datap_std[-1],
|
90 |
-
experiment_name=sheet_name, legend_position=legend_position,
|
91 |
-
params_position=params_position, show_legend=show_legend,
|
92 |
-
show_params=show_params, style=style, line_color=line_color,
|
93 |
-
point_color=point_color, line_style=line_style,
|
94 |
-
marker_style=marker_style)
|
95 |
-
figures.append(fig)
|
96 |
-
|
97 |
-
# Convertir los gráficos en imágenes
|
98 |
-
image_list = []
|
99 |
-
for fig in figures:
|
100 |
-
buf = io.BytesIO()
|
101 |
-
fig.savefig(buf, format='png')
|
102 |
-
buf.seek(0)
|
103 |
-
image = Image.open(buf)
|
104 |
-
image_list.append(image)
|
105 |
-
|
106 |
-
# Análisis básico generado
|
107 |
-
analysis = f"Se han procesado {len(excel_data.sheet_names)} hojas con el modelo {model_type}."
|
108 |
-
|
109 |
-
return image_list, analysis
|
110 |
-
|
111 |
-
# Crear y lanzar la interfaz
|
112 |
-
demo = create_interface(process_and_plot)
|
113 |
-
demo.launch(share=True)
|
|
|
2 |
import pandas as pd
|
3 |
import io
|
4 |
from PIL import Image
|
5 |
+
from bioprocess_model import BioprocessModel # Importa
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|