Update app.py
Browse files
app.py
CHANGED
@@ -9,7 +9,6 @@ model = joblib.load(model_path)
|
|
9 |
|
10 |
# Função para prever utilizando o modelo
|
11 |
def predict_tiebreak(df):
|
12 |
-
# Função para calcular as métricas
|
13 |
def calculate_features(row):
|
14 |
odds_min = min(row['Odds 1'], row['Odds 2'])
|
15 |
odds_max = max(row['Odds 1'], row['Odds 2'])
|
@@ -18,14 +17,11 @@ def predict_tiebreak(df):
|
|
18 |
sum_prob = (1 / odds_min) + (1 / odds_max)
|
19 |
return pd.Series([odds_ratio, diff_log_odds, sum_prob])
|
20 |
|
21 |
-
# Calcular as features
|
22 |
df[['Odds_Ratio', 'Diff_Log_Odds', 'Sum_Prob']] = df.apply(calculate_features, axis=1)
|
23 |
|
24 |
-
# Realizar a previsão com o modelo
|
25 |
features = df[['Odds_Ratio', 'Diff_Log_Odds', 'Sum_Prob']]
|
26 |
df['Probability'] = model.predict_proba(features)[:, 1]
|
27 |
|
28 |
-
# Verificar a decisão de entrar ou não na aposta com base no threshold
|
29 |
best_threshold = 0.9420000000000005
|
30 |
df['entrada'] = df['Probability'] >= best_threshold
|
31 |
df = df[df['entrada'] == True]
|
@@ -33,26 +29,21 @@ def predict_tiebreak(df):
|
|
33 |
|
34 |
# Função para carregar o arquivo Excel e prever
|
35 |
def predict_from_excel(file):
|
36 |
-
# Carregar o arquivo Excel em um DataFrame
|
37 |
df = pd.read_excel(file)
|
38 |
-
|
39 |
-
# Prever utilizando o modelo
|
40 |
df_predictions = predict_tiebreak(df)
|
41 |
-
|
42 |
-
# Retornar o DataFrame resultante como um arquivo Excel
|
43 |
output_file = "predictions.xlsx"
|
44 |
df_predictions.to_excel(output_file, index=False)
|
45 |
return output_file
|
46 |
|
47 |
-
# Interface Gradio
|
48 |
-
inputs = gr.
|
49 |
-
outputs = gr.
|
50 |
|
51 |
# Criando a interface
|
52 |
-
gr.Interface(
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
|
|
9 |
|
10 |
# Função para prever utilizando o modelo
|
11 |
def predict_tiebreak(df):
|
|
|
12 |
def calculate_features(row):
|
13 |
odds_min = min(row['Odds 1'], row['Odds 2'])
|
14 |
odds_max = max(row['Odds 1'], row['Odds 2'])
|
|
|
17 |
sum_prob = (1 / odds_min) + (1 / odds_max)
|
18 |
return pd.Series([odds_ratio, diff_log_odds, sum_prob])
|
19 |
|
|
|
20 |
df[['Odds_Ratio', 'Diff_Log_Odds', 'Sum_Prob']] = df.apply(calculate_features, axis=1)
|
21 |
|
|
|
22 |
features = df[['Odds_Ratio', 'Diff_Log_Odds', 'Sum_Prob']]
|
23 |
df['Probability'] = model.predict_proba(features)[:, 1]
|
24 |
|
|
|
25 |
best_threshold = 0.9420000000000005
|
26 |
df['entrada'] = df['Probability'] >= best_threshold
|
27 |
df = df[df['entrada'] == True]
|
|
|
29 |
|
30 |
# Função para carregar o arquivo Excel e prever
|
31 |
def predict_from_excel(file):
|
|
|
32 |
df = pd.read_excel(file)
|
|
|
|
|
33 |
df_predictions = predict_tiebreak(df)
|
|
|
|
|
34 |
output_file = "predictions.xlsx"
|
35 |
df_predictions.to_excel(output_file, index=False)
|
36 |
return output_file
|
37 |
|
38 |
+
# Interface Gradio usando a nova API de componentes
|
39 |
+
inputs = gr.File(label="Upload Excel File")
|
40 |
+
outputs = gr.File(label="Download Predictions Excel")
|
41 |
|
42 |
# Criando a interface
|
43 |
+
gr.Interface(
|
44 |
+
fn=predict_from_excel,
|
45 |
+
inputs=inputs,
|
46 |
+
outputs=outputs,
|
47 |
+
title="Previsão de Tiebreaks",
|
48 |
+
description="Faça o upload de um arquivo Excel contendo dados no formato final_df para prever a probabilidade de menos de 1.5 tiebreaks e verificar se deve entrar na aposta."
|
49 |
+
).launch()
|