Spaces:
Runtime error
Runtime error
init
Browse files- app.py +57 -0
- diagramas/Tab_1.png +0 -0
- diagramas/Tab_2.png +0 -0
- diagramas/Tab_3.png +0 -0
- requirements.txt +3 -0
app.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Imports
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import numpy as np
|
| 4 |
+
import gradio as gr
|
| 5 |
+
import statsmodels.api as sm
|
| 6 |
+
from io import BytesIO
|
| 7 |
+
import os
|
| 8 |
+
|
| 9 |
+
# Hay que definir una funcion que tome el archivo, lo lea y aplique los filtros segun un listado criterios
|
| 10 |
+
def read_pdf(file):
|
| 11 |
+
file_name = file.name
|
| 12 |
+
global df
|
| 13 |
+
df = pd.read_excel(file_name)
|
| 14 |
+
return df.head(10)
|
| 15 |
+
|
| 16 |
+
# Esta funcion aplica el filtro seleccionado
|
| 17 |
+
def apply_filter(criteria):
|
| 18 |
+
global df
|
| 19 |
+
# Si los datos no se leyeron correctamente
|
| 20 |
+
if df is None:
|
| 21 |
+
return pd.DataFrame() # Devuelvo un df vacio
|
| 22 |
+
# Aplico el filtro seleccionado
|
| 23 |
+
if criteria == 'Criterio 1':
|
| 24 |
+
filter_cond = (df['cyl']>=6) & (df['hp']>=150)
|
| 25 |
+
elif criteria == 'Criterio 2':
|
| 26 |
+
filter_cond = df['gear']>4
|
| 27 |
+
elif criteria == 'Criterio 3':
|
| 28 |
+
filter_cond = (df['disp']>150) & (df['disp']<230) & (df['qsec']>16) & (df['qsec']<18)
|
| 29 |
+
|
| 30 |
+
global filtered_df
|
| 31 |
+
filtered_df = df[filter_cond]
|
| 32 |
+
return filtered_df
|
| 33 |
+
|
| 34 |
+
def download_file(filter_df):
|
| 35 |
+
output_name = 'output.xlsx'
|
| 36 |
+
filter_df.to_excel(output_name)
|
| 37 |
+
return output_name
|
| 38 |
+
|
| 39 |
+
with gr.Blocks() as demo:
|
| 40 |
+
with gr.Tab(label='Carga Archivo'):
|
| 41 |
+
input_file = gr.components.File(label='Excel-CSV File', file_types=['.xlsx', '.xls', '.csv'], file_count='single')
|
| 42 |
+
send_file = gr.Button(label='Cargar')
|
| 43 |
+
|
| 44 |
+
with gr.Tab(label='Ajustes'):
|
| 45 |
+
table = gr.DataFrame(label='Tabla')
|
| 46 |
+
filter_select = gr.Dropdown(choices=['Criterio 1', 'Criterio 2', 'Criterio 3'], label='Selección de criterios')
|
| 47 |
+
apply_filter_button = gr.Button(label='Aplicar filtro')
|
| 48 |
+
|
| 49 |
+
with gr.Tab(label='Descarga'):
|
| 50 |
+
# output_file = gr.components.File(label='Descarga de archivo', file_count='single')
|
| 51 |
+
# download_format = gr.Dropdown(choices=['csv', 'xlsx'], label='Format')
|
| 52 |
+
download_button = gr.Button(label='Descarga de archivo')
|
| 53 |
+
download_button.click(fn=download_file, inputs=[table], outputs=gr.components.File(label="Download Processed Excel file"))
|
| 54 |
+
|
| 55 |
+
# Funcionalidades
|
| 56 |
+
send_file.click(fn=read_pdf, inputs=[input_file], outputs=table)
|
| 57 |
+
apply_filter_button.click(fn=apply_filter, inputs=[filter_select], outputs=table)
|
diagramas/Tab_1.png
ADDED
|
diagramas/Tab_2.png
ADDED
|
diagramas/Tab_3.png
ADDED
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
pandas
|
| 3 |
+
openpyxl
|