File size: 6,570 Bytes
f3f77c0 67e3976 f3f77c0 67e3976 f3f77c0 67e3976 f3f77c0 67e3976 f3f77c0 67e3976 f3f77c0 67e3976 f3f77c0 67e3976 f3f77c0 67e3976 f3f77c0 67e3976 f3f77c0 67e3976 f3f77c0 67e3976 f3f77c0 67e3976 f3f77c0 67e3976 f3f77c0 67e3976 f3f77c0 67e3976 f3f77c0 67e3976 f3f77c0 67e3976 f3f77c0 2e99c86 f3f77c0 1d9c895 f3f77c0 2e99c86 bcf3afd 2e99c86 67e3976 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# UI.py
import gradio as gr
def create_interface():
with gr.Blocks() as demo:
gr.Markdown("# Aplicaci贸n de Modelado de Bioprocesos con Integraci贸n de Yi-Coder")
file_input = gr.File(label="Subir Archivo Excel")
MAX_EQUATIONS = 3
biomass_equations = []
biomass_params = []
biomass_bounds = []
substrate_equations = []
substrate_params = []
substrate_bounds = []
product_equations = []
product_params = []
product_bounds = []
def create_model_inputs(model_name, equations_list, params_list, bounds_list):
with gr.Column():
gr.Markdown(f"### Modelos de {model_name}")
for i in range(MAX_EQUATIONS):
with gr.Row(visible=(i == 0)) as row:
equation_input = gr.Textbox(
label=f"Ecuaci贸n del Modelo {model_name} {i+1}",
placeholder="Introduce la ecuaci贸n en t茅rminos de t y par谩metros",
lines=1,
value="" if i > 0 else "Ecuaci贸n por defecto"
)
params_input = gr.Textbox(
label=f"Par谩metros del Modelo {model_name} {i+1}",
placeholder="Par谩metros separados por comas",
lines=1,
value="" if i > 0 else "Par谩metros"
)
bounds_input = gr.Textbox(
label=f"Limites del Modelo {model_name} {i+1}",
placeholder="(inferior, superior) para cada par谩metro",
lines=1
)
equations_list.append((row, equation_input))
params_list.append(params_input)
bounds_list.append(bounds_input)
add_btn = gr.Button(f"Agregar Ecuaci贸n de {model_name}")
remove_btn = gr.Button(f"Eliminar Ecuaci贸n de {model_name}")
return add_btn, remove_btn
with gr.Accordion("Definici贸n de Modelos", open=True):
with gr.Row():
with gr.Column():
add_biomass_btn, remove_biomass_btn = create_model_inputs(
"Biomasa", biomass_equations, biomass_params, biomass_bounds
)
with gr.Column():
add_substrate_btn, remove_substrate_btn = create_model_inputs(
"Sustrato", substrate_equations, substrate_params, substrate_bounds
)
with gr.Column():
add_product_btn, remove_product_btn = create_model_inputs(
"Producto", product_equations, product_params, product_bounds
)
legend_position = gr.Radio(
choices=["upper left", "upper right", "lower left", "lower right", "best"],
label="Posici贸n de la Leyenda",
value="best"
)
show_legend = gr.Checkbox(label="Mostrar Leyenda", value=True)
show_params = gr.Checkbox(label="Mostrar Par谩metros", value=True)
simulate_btn = gr.Button("Simular")
with gr.Row():
output_gallery = gr.Gallery(label="Resultados", columns=2, height='auto')
analysis_output = gr.Textbox(label="An谩lisis de Yi-Coder", lines=15)
biomass_eq_count = gr.Number(value=1, visible=False)
substrate_eq_count = gr.Number(value=1, visible=False)
product_eq_count = gr.Number(value=1, visible=False)
def add_equation(equations_list, eq_count):
eq_count = min(eq_count + 1, MAX_EQUATIONS)
for i, (row, _) in enumerate(equations_list):
row.visible = i < eq_count
return [row.update(visible=row.visible) for row, _ in equations_list], eq_count
def remove_equation(equations_list, eq_count):
eq_count = max(eq_count - 1, 1)
for i, (row, _) in enumerate(equations_list):
row.visible = i < eq_count
return [row.update(visible=row.visible) for row, _ in equations_list], eq_count
add_biomass_btn.click(
fn=lambda eq_count: add_equation(biomass_equations, eq_count),
inputs=biomass_eq_count,
outputs=[*[row for row, _ in biomass_equations], biomass_eq_count]
)
remove_biomass_btn.click(
fn=lambda eq_count: remove_equation(biomass_equations, eq_count),
inputs=biomass_eq_count,
outputs=[*[row for row, _ in biomass_equations], biomass_eq_count]
)
add_substrate_btn.click(
fn=lambda eq_count: add_equation(substrate_equations, eq_count),
inputs=substrate_eq_count,
outputs=[*[row for row, _ in substrate_equations], substrate_eq_count]
)
remove_substrate_btn.click(
fn=lambda eq_count: remove_equation(substrate_equations, eq_count),
inputs=substrate_eq_count,
outputs=[*[row for row, _ in substrate_equations], substrate_eq_count]
)
add_product_btn.click(
fn=lambda eq_count: add_equation(product_equations, eq_count),
inputs=product_eq_count,
outputs=[*[row for row, _ in product_equations], product_eq_count]
)
remove_product_btn.click(
fn=lambda eq_count: remove_equation(product_equations, eq_count),
inputs=product_eq_count,
outputs=[*[row for row, _ in product_equations], product_eq_count]
)
simulate_inputs = [
file_input,
*[eq_input for row, eq_input in biomass_equations],
*biomass_params,
*biomass_bounds,
*[eq_input for row, eq_input in substrate_equations],
*substrate_params,
*substrate_bounds,
*[eq_input for row, eq_input in product_equations],
*product_params,
*product_bounds,
legend_position,
show_legend,
show_params,
biomass_eq_count,
substrate_eq_count,
product_eq_count
]
# At the point where you use process_and_plot:
simulate_btn.click(
fn=process_and_plot,
inputs=simulate_inputs,
outputs=[output_gallery, analysis_output]
)
return demo
|