C2MV commited on
Commit
f33a271
1 Parent(s): 9abc7c9

Update UI.py

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