import gradio as gr import pandas as pd import statsmodels.api as sm import numpy as np df = pd.read_excel('MOD_VC.xlsx', 'DF') # Separar as variáveis independentes (X) e dependente (y) X = df[['AREA', 'TEST', 'PAV', 'POS', 'RB']] y = df['VU'] X_with_constant = sm.add_constant(X) model = sm.OLS(y, X_with_constant) results = model.fit() def predict(input_df): # Processamento da planilha de input input_df[['AREA', 'TEST']] = np.log(input_df[['AREA', 'TEST']]) input_df['RB'] = 1/input_df['RB'] # Preparar dados para predição X_new = np.array(input_df) X_new_with_constant = np.insert(X_new, 0, 1, axis=1) # Fazer previsões y_pred = results.predict(X_new_with_constant) ci = results.get_prediction(X_new_with_constant).conf_int() inter_conf = np.exp(ci) # Adicionar previsões e intervalos de confiança à planilha input_df['Predicted'] = np.exp(y_pred) input_df['CI Lower'] = inter_conf[:, 0] input_df['CI Upper'] = inter_conf[:, 1] return input_df # Interface Gradio iface = gr.Interface(fn=predict, inputs="dataframe", outputs="dataframe") iface.launch()