rairo commited on
Commit
a7d59ca
·
verified ·
1 Parent(s): a22e862

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -20
app.py CHANGED
@@ -30,26 +30,66 @@ def get_player_stats(player_id):
30
  def prediction_section():
31
  st.header("🧠 Prospect Potential Prediction")
32
 
33
- # Get available teams
34
- schedule = get_schedule()
35
- teams = {team['team']['id']: team['team']['name']
36
- for game in schedule['dates'][0]['games']
37
- for team in [game['teams']['home']['team'], game['teams']['away']['team']]}
38
-
39
- col1, col2 = st.columns(2)
40
- with col1:
41
- team_id = st.selectbox("Select Team", options=teams.keys(), format_func=lambda x: teams[x])
42
-
43
- with col2:
44
- roster = get_roster(team_id)['roster']
45
- players = {p['person']['id']: p['person']['fullName'] for p in roster}
46
- player_id = st.selectbox("Select Prospect", options=players.keys(), format_func=lambda x: players[x])
47
-
48
- if st.button("Analyze Prospect"):
49
- stats = get_player_stats(player_id)
50
- # Add your ML model here (placeholder example)
51
- st.success(f"Predicted WAR in 3 years: 4.2 (Sample Output)")
52
- st.json(stats) # Show raw data for inspection
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
 
54
 
55
  def comparison_tool():
 
30
  def prediction_section():
31
  st.header("🧠 Prospect Potential Prediction")
32
 
33
+ try:
34
+ # Get available teams with error handling
35
+ schedule = get_schedule()
36
+ teams = {}
37
+
38
+ # Safely navigate through possible missing keys
39
+ if 'dates' in schedule and len(schedule['dates']) > 0:
40
+ for date in schedule['dates']:
41
+ if 'games' in date:
42
+ for game in date['games']:
43
+ for team_type in ['home', 'away']:
44
+ team = game['teams'][team_type].get('team', {})
45
+ team_id = team.get('id')
46
+ team_name = team.get('name')
47
+ if team_id and team_name:
48
+ teams[team_id] = team_name
49
+
50
+ if not teams:
51
+ st.warning("No team data available. Using default teams.")
52
+ teams = {119: "Los Angeles Dodgers"} # Fallback
53
+
54
+ col1, col2 = st.columns(2)
55
+ with col1:
56
+ team_id = st.selectbox("Select Team", options=teams.keys(), format_func=lambda x: teams[x])
57
+
58
+ with col2:
59
+ try:
60
+ roster = get_roster(team_id).get('roster', [])
61
+ players = {}
62
+ for p in roster:
63
+ person = p.get('person', {})
64
+ players[person.get('id')] = person.get('fullName', 'Unknown Player')
65
+
66
+ if not players:
67
+ st.error("No players found for this team")
68
+ return
69
+
70
+ player_id = st.selectbox("Select Prospect", options=players.keys(), format_func=lambda x: players[x])
71
+
72
+ except Exception as e:
73
+ st.error(f"Error loading roster: {str(e)}")
74
+ return
75
+
76
+ if st.button("Analyze Prospect"):
77
+ try:
78
+ stats = get_player_stats(player_id)
79
+ # Add proper error handling for stats data
80
+ if not stats:
81
+ st.error("No player stats available")
82
+ return
83
+
84
+ # Placeholder for actual model prediction
85
+ st.success(f"Predicted WAR in 3 years: 4.2 (Sample Output)")
86
+ st.json(stats) # Show raw data for inspection
87
+
88
+ except Exception as e:
89
+ st.error(f"Analysis failed: {str(e)}")
90
+
91
+ except Exception as e:
92
+ st.error(f"Failed to load schedule data: {str(e)}")
93
 
94
 
95
  def comparison_tool():