joaomaia commited on
Commit
a103715
·
verified ·
1 Parent(s): 52fb0f2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import joblib
3
+ import numpy as np
4
+
5
+ # Carregar o modelo serializado
6
+ model = joblib.load("tiebreak_model.pkl")
7
+
8
+ # Função para realizar a previsão
9
+ def predict_tiebreak(win_odds, loser_odds):
10
+ # Calculando as features
11
+ odds_ratio = win_odds / loser_odds
12
+ log_odds_w = np.log(win_odds)
13
+ log_odds_l = np.log(loser_odds)
14
+ prob_w = 1 / win_odds
15
+ prob_l = 1 / loser_odds
16
+ odds_spread = abs(loser_odds - win_odds)
17
+
18
+ # Criando o vetor de features para o modelo
19
+ features = np.array([[odds_ratio, log_odds_w, log_odds_l, prob_w, prob_l, odds_spread]])
20
+
21
+ # Realizando a previsão
22
+ prob = model.predict_proba(features)[0, 1] # Probabilidade da classe 1 (menos de 1.5 tiebreaks)
23
+
24
+ # Calculando a odds mínima
25
+ odds_minima = 1 / prob
26
+
27
+ # Retornando os valores arredondados
28
+ return round(prob, 2), round(odds_minima, 2)
29
+
30
+ # Interface Gradio
31
+ inputs = [gr.inputs.Number(label="Win Odds"), gr.inputs.Number(label="Loser Odds")]
32
+ outputs = [gr.outputs.Textbox(label="Probabilidade de menos de 1.5 Tiebreaks"), gr.outputs.Textbox(label="Odds Mínima")]
33
+
34
+ # Criação da interface
35
+ gr.Interface(fn=predict_tiebreak, inputs=inputs, outputs=outputs, title="Previsão de Tiebreaks",
36
+ description="Insira as odds de vitória e derrota para prever a probabilidade de haver menos de 1.5 tiebreaks e calcular as odds mínimas.").launch()