File size: 5,008 Bytes
f3f77c0 ee18ffc 65a427d f3f77c0 f33a271 f3f77c0 ee18ffc f3f77c0 65a427d ee18ffc 65a427d f33a271 f3f77c0 ee18ffc 65a427d ee18ffc f33a271 ee18ffc 65a427d 2e99c86 ee18ffc 65a427d ee18ffc 65a427d |
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 |
import gradio as gr
import pandas as pd
import io
from PIL import Image
from matplotlib import pyplot as plt
from bioprocess_model import BioprocessModel # Asegúrate de que BioprocessModel esté en su propio archivo
def create_interface(process_fn):
with gr.Blocks() as demo:
gr.Markdown("# Interfaz de Usuario para el Procesamiento de Datos de Bioproceso")
# Inputs de archivo y parámetros
file_input = gr.File(label="Subir archivo Excel con los datos", file_types=[".xls", ".xlsx"])
with gr.Row():
with gr.Column():
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)
with gr.Column():
params_positions = ["upper left", "upper right", "lower left", "lower right", "outside right"]
params_position = gr.Radio(
choices=params_positions,
label="Posición de los parámetros",
value="upper right"
)
show_params = gr.Checkbox(label="Mostrar Parámetros", value=True)
# Parámetros adicionales
model_type = gr.Radio(["logistic", "luedeking-piret"], label="Tipo de Modelo", value="logistic")
mode = gr.Radio(["independent", "average", "combinado"], label="Modo de Análisis", value="independent")
# Estilo gráfico
styles = ['white', 'dark', 'whitegrid', 'darkgrid', 'ticks']
style_dropdown = gr.Dropdown(choices=styles, label="Selecciona el estilo de gráfico", value='whitegrid')
line_color_picker = gr.ColorPicker(label="Color de la línea", value='#0000FF')
point_color_picker = gr.ColorPicker(label="Color de los puntos", value='#000000')
line_style_options = ['-', '--', '-.', ':']
line_style_dropdown = gr.Dropdown(choices=line_style_options, label="Estilo de línea", value='-')
marker_style_options = ['o', 's', '^', 'v', 'D', 'x', '+', '*']
marker_style_dropdown = gr.Dropdown(choices=marker_style_options, label="Estilo de punto", value='o')
# Botón de Procesar
process_button = gr.Button("Procesar")
# Salida
output_gallery = gr.Gallery(label="Gráfico Generado", columns=2, height='auto')
output_text = gr.Textbox(label="Análisis Generado", lines=10)
# Conectar el botón con la función de procesamiento
process_button.click(
fn=process_fn,
inputs=[file_input, legend_position, params_position, model_type, mode, style_dropdown,
line_color_picker, point_color_picker, line_style_dropdown, marker_style_dropdown,
show_legend, show_params],
outputs=[output_gallery, output_text]
)
return demo
def process_and_plot(file, legend_position, params_position, model_type, mode, style,
line_color, point_color, line_style, marker_style, show_legend, show_params):
# Leer el archivo Excel proporcionado
excel_data = pd.ExcelFile(file.name)
figures = []
model = BioprocessModel()
model.fit_model(model_type)
for sheet_name in excel_data.sheet_names:
df = pd.read_excel(excel_data, sheet_name=sheet_name)
model.process_data(df)
# Obtener los datos de tiempo, biomasa, sustrato y producto
time = model.time
biomass = model.dataxp[-1]
substrate = model.datasp[-1]
product = model.datapp[-1]
# Generar los gráficos
fig = model.plot_combined_results(time, biomass, substrate, product,
model.dataxp[-1], model.datasp[-1], model.datapp[-1],
model.datax_std[-1], model.datas_std[-1], model.datap_std[-1],
experiment_name=sheet_name, legend_position=legend_position,
params_position=params_position, show_legend=show_legend,
show_params=show_params, style=style, line_color=line_color,
point_color=point_color, line_style=line_style,
marker_style=marker_style)
figures.append(fig)
# Convertir los gráficos en imágenes
image_list = []
for fig in figures:
buf = io.BytesIO()
fig.savefig(buf, format='png')
buf.seek(0)
image = Image.open(buf)
image_list.append(image)
# Análisis básico generado
analysis = f"Se han procesado {len(excel_data.sheet_names)} hojas con el modelo {model_type}."
return image_list, analysis
# Crear y lanzar la interfaz
demo = create_interface(process_and_plot)
demo.launch(share=True)
|