AlvaroMros commited on
Commit
55723a4
·
1 Parent(s): f3ecc65

Update prediction output to show winner and confidence

Browse files

Modified the predict_fight function and Gradio interface to return and display both the predicted winner and the confidence percentage in separate fields. Improved error handling to match the new output format and updated the app title with emojis for better presentation.

Files changed (1) hide show
  1. app.py +10 -7
app.py CHANGED
@@ -59,19 +59,19 @@ def predict_fight(model_name, fighter1_name, fighter2_name):
59
  if prediction_result and prediction_result.get('winner'):
60
  winner = prediction_result['winner']
61
  prob = prediction_result['probability']
62
- return f"Predicted Winner: {winner} ({prob:.1%})"
63
  else:
64
- return "Could not make a prediction. Is one of the fighters new or not in the dataset?"
65
 
66
  except FileNotFoundError:
67
- return f"Error: Model file '{model_name}' not found."
68
  except Exception as e:
69
  print(f"An error occurred during prediction: {e}")
70
- return f"An error occurred: {e}"
71
 
72
  # --- Gradio Interface ---
73
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
74
- gr.Markdown("# UFC Fight Predictor")
75
  gr.Markdown("Select a prediction model and enter two fighter names to predict the outcome.")
76
 
77
  with gr.Column():
@@ -85,12 +85,15 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
85
  fighter2_input = gr.Textbox(label="Fighter 2", placeholder="e.g., Stipe Miocic")
86
 
87
  predict_button = gr.Button("Predict Winner")
88
- output_text = gr.Textbox(label="Prediction Result", interactive=False)
 
 
 
89
 
90
  predict_button.click(
91
  fn=predict_fight,
92
  inputs=[model_dropdown, fighter1_input, fighter2_input],
93
- outputs=output_text
94
  )
95
 
96
  # --- Launch the App ---
 
59
  if prediction_result and prediction_result.get('winner'):
60
  winner = prediction_result['winner']
61
  prob = prediction_result['probability']
62
+ return winner, f"{prob:.1%}"
63
  else:
64
+ return "Could not make a prediction.", ""
65
 
66
  except FileNotFoundError:
67
+ return f"Error: Model file '{model_name}' not found.", ""
68
  except Exception as e:
69
  print(f"An error occurred during prediction: {e}")
70
+ return f"An error occurred: {e}", ""
71
 
72
  # --- Gradio Interface ---
73
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
74
+ gr.Markdown("# 🥋 UFC Fight Predictor 🥊")
75
  gr.Markdown("Select a prediction model and enter two fighter names to predict the outcome.")
76
 
77
  with gr.Column():
 
85
  fighter2_input = gr.Textbox(label="Fighter 2", placeholder="e.g., Stipe Miocic")
86
 
87
  predict_button = gr.Button("Predict Winner")
88
+
89
+ with gr.Column():
90
+ winner_output = gr.Textbox(label="Predicted Winner", interactive=False)
91
+ prob_output = gr.Textbox(label="Confidence", interactive=False)
92
 
93
  predict_button.click(
94
  fn=predict_fight,
95
  inputs=[model_dropdown, fighter1_input, fighter2_input],
96
+ outputs=[winner_output, prob_output]
97
  )
98
 
99
  # --- Launch the App ---