|
import gradio as gr |
|
import pandas as pd |
|
|
|
def create_interface(process_fn): |
|
with gr.Blocks() as demo: |
|
gr.Markdown("# Interfaz de Usuario para el Procesamiento de Datos de Bioproceso") |
|
|
|
|
|
file_input = gr.File(label="Subir archivo Excel con los datos", file_types=[".xls", ".xlsx"]) |
|
|
|
|
|
process_button = gr.Button("Procesar") |
|
|
|
|
|
output_image = gr.Image(label="Gráfico Generado") |
|
output_text = gr.Textbox(label="Análisis Generado", lines=10) |
|
|
|
|
|
process_button.click( |
|
fn=process_fn, |
|
inputs=[file_input], |
|
outputs=[output_image, output_text] |
|
) |
|
|
|
return demo |
|
|
|
def process_and_plot(file): |
|
|
|
combined_data = read_excel_data(file.name) |
|
|
|
|
|
|
|
|
|
|
|
|
|
return combined_data.head(), "Análisis de los datos realizados" |
|
|
|
|
|
def read_excel_data(file_path): |
|
excel_data = pd.ExcelFile(file_path) |
|
all_data = [] |
|
|
|
for sheet in excel_data.sheet_names: |
|
df = pd.read_excel(excel_data, sheet_name=sheet) |
|
|
|
|
|
df_clean = df.iloc[:, :4] |
|
df_clean.columns = ['Tiempo', 'Biomasa', 'Sustrato', 'Producto'] |
|
|
|
all_data.append(df_clean) |
|
|
|
combined_data = pd.concat(all_data, ignore_index=True) |
|
|
|
return combined_data |
|
|