fschwartzer commited on
Commit
6dc42d0
1 Parent(s): f3cd7aa

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ import statsmodels.api as sm
4
+ import numpy as np
5
+
6
+ df = pd.read_excel('MOD_VC.xlsx', 'DF')
7
+
8
+ # Separar as variáveis independentes (X) e dependente (y)
9
+ X = df[['AREA', 'TEST', 'PAV', 'POS', 'RB']]
10
+ y = df['VU']
11
+
12
+ X_with_constant = sm.add_constant(X)
13
+ model = sm.OLS(y, X_with_constant)
14
+ results = model.fit()
15
+
16
+ def predict(input_df):
17
+ # Processamento da planilha de input
18
+ input_df[['AREA', 'TEST']] = np.log(input_df[['AREA', 'TEST']])
19
+ input_df['RB'] = 1/input_df['RB']
20
+
21
+ # Preparar dados para predição
22
+ X_new = np.array(input_df)
23
+ X_new_with_constant = np.insert(X_new, 0, 1, axis=1)
24
+
25
+ # Fazer previsões
26
+ y_pred = results.predict(X_new_with_constant)
27
+ ci = results.get_prediction(X_new_with_constant).conf_int()
28
+ inter_conf = np.exp(ci)
29
+
30
+ # Adicionar previsões e intervalos de confiança à planilha
31
+ input_df['Predicted'] = np.exp(y_pred)
32
+ input_df['CI Lower'] = inter_conf[:, 0]
33
+ input_df['CI Upper'] = inter_conf[:, 1]
34
+
35
+ return input_df
36
+
37
+ # Interface Gradio
38
+ iface = gr.Interface(fn=predict, inputs="dataframe", outputs="dataframe")
39
+ iface.launch()