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 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
import streamlit as st
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
import base64
from io import StringIO



# Background image setup
def set_bg():
    bg_style = """
    <style>
    .stApp {
        background-color: beige;
        color: black;
    }
    .text-box {
        background-color: rgba(255, 255, 255, 0.8);
        padding: 25px;
        border-radius: 10px;
        margin-top: 20px;
    }
    h1, h2, h3, h4, h5, h6 {
        color: black !important;
        text-align: center;
    }
    .kpi-card {
        background-color: rgba(0, 0, 0, 0.05);
        color: black;
    }
    .kpi-card .label {
        color: #333;
    }
    </style>
    """
    st.markdown(bg_style, unsafe_allow_html=True)


# Apply beige background
set_bg()


















# Load dataset
df = pd.read_csv(r"cleaned.csv")
import streamlit.components.v1 as components

# App Title
col1, col2 = st.columns([2, 1])

with col1:
    st.title("πŸš€ Cricket Player Career Stats Viewer")
    


with col2:
    components.html(
        """
        <script src="https://unpkg.com/@dotlottie/player-component@2.7.12/dist/dotlottie-player.mjs" type="module"></script>
        <dotlottie-player 
            src="https://lottie.host/4a7cdc9a-67d6-4509-a98d-f97862e1b596/tVTWTBvZ2a.lottie" 
            background="transparent" 
            speed="1" 
            style="width: 300px; height: 300px;" 
            loop autoplay>
        </dotlottie-player>
        """,
        height=250,
        width=200
    )

# Player selection
player_name = st.selectbox("Select a Player", df['Player'].unique())


# Filter player data
player_data = df[df['Player'] == player_name].iloc[0]

# Extract player ODI stats
runs = player_data["batting_Runs_ODI"]
avg = player_data["batting_Average_ODI"]
sr = player_data["batting_SR_ODI"]
wickets = player_data["bowling_ODI_Wickets"]
hundreds = player_data["batting_100s_ODI"]
fifties = player_data["batting_50s_ODI"]

# Custom CSS for sleek KPI cards
st.markdown("""
<style>
.kpi-container {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    margin-top: 20px;
    margin-bottom: 30px;
}
.kpi-card {
    flex: 1 1 16%;
    background-color: #f0e6d6;  /* Light beige tone */
    border-radius: 12px;
    padding: 15px;
    margin: 10px;
    text-align: center;
    color: black;
    font-family: 'Segoe UI', sans-serif;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}
.kpi-card .label {
    font-size: 14px;
    color: #333333;
    margin-bottom: 5px;
}
.kpi-card .value {
    font-size: 26px;
    font-weight: bold;
    color: #000000;
}
</style>
""", unsafe_allow_html=True)


# Section header
st.markdown("<h2 style='color:white;'>πŸ“Š Player Performance (ODI)</h2>", unsafe_allow_html=True)

# KPI card container
st.markdown(f"""
<div class="kpi-container">
    <div class="kpi-card">
        <div class="label">🏏 Runs</div>
        <div class="value">{runs}</div>
    </div>
    <div class="kpi-card">
        <div class="label">πŸ“Š Average</div>
        <div class="value">{avg:.2f}</div>
    </div>
    <div class="kpi-card">
        <div class="label">⚑ Strike Rate</div>
        <div class="value">{sr:.2f}</div>
    </div>
    <div class="kpi-card">
        <div class="label">🎯 Wickets</div>
        <div class="value">{wickets}</div>
    </div>
    <div class="kpi-card">
        <div class="label">πŸ’― 100s</div>
        <div class="value">{hundreds}</div>
    </div>

</div>
""", unsafe_allow_html=True)



































formats = ['Test', 'ODI', 'T20', 'IPL']

# ---- Batting Career Summary ----


st.subheader("Batting Career Summary")
batting_summary = []

for fmt in formats:
    batting_summary.append([
        fmt,
        player_data[f'Matches_{fmt}'],
        player_data[f'batting_Innings_{fmt}'],
        player_data[f'batting_Runs_{fmt}'],
        player_data[f'batting_Balls_{fmt}'],
        player_data[f'batting_Highest_{fmt}'],
        player_data[f'batting_Average_{fmt}'],
        player_data[f'batting_SR_{fmt}'],
        player_data[f'batting_Not Out_{fmt}'],
        player_data[f'batting_Fours_{fmt}'],
        player_data[f'batting_Sixes_{fmt}'],
        player_data[f'batting_50s_{fmt}'],
        player_data[f'batting_100s_{fmt}'],
        player_data[f'batting_200s_{fmt}']
    ])

batting_df = pd.DataFrame(batting_summary, columns=[
    'Format', 'Matches', 'Innings', 'Runs', 'Balls Faced', 'Highest', 'Average',
    'Strike Rate', 'Not Out', '4s', '6s', '50s', '100s', '200s'
])
st.dataframe(batting_df.set_index("Format"),use_container_width=True)

# ---- Bowling Career Summary ----
st.subheader("Bowling Career Summary")
bowling_summary = []

for fmt in formats:
    bowling_summary.append([
        fmt,
        player_data[f'bowling_{fmt}_Innings'],
        player_data[f'bowling_{fmt}_Balls'],
        player_data[f'bowling_{fmt}_Runs'],
        player_data[f'bowling_{fmt}_Wickets'],
        player_data[f'bowling_{fmt}_Avg'],
        player_data[f'bowling_{fmt}_Eco'],
        player_data[f'bowling_{fmt}_SR'],
        player_data[f'bowling_{fmt}_BBI'],
        player_data[f'bowling_{fmt}_5w'],
        player_data[f'bowling_{fmt}_10w']
    ])

bowling_df = pd.DataFrame(bowling_summary, columns=[
    'Format', 'Innings', 'Balls', 'Runs', 'Wickets', 'Avg', 'Economy',
    'Strike Rate', 'BBI', '5w', '10w'
])
st.dataframe(bowling_df.set_index("Format"))

# ---- Plotly Pie Chart: Matches per Format ----
st.subheader("Matches Played per Format")
match_counts = [player_data[f'Matches_{fmt}'] for fmt in formats]


col1, col2 = st.columns(2)

# ---- Pie Chart: Match Distribution ----
with col1:
    fig1 = px.pie(
        names=formats,
        values=match_counts,
        title="Match Distribution by Format",
        hole=0.4
    )
    fig1.update_layout(
        paper_bgcolor='rgba(0, 0, 0, 0.8)',   # outer background
        plot_bgcolor='rgba(0, 0, 0, 0.7)',    # plot area
        font=dict(color='white')
    )
    st.plotly_chart(fig1, use_container_width=True, key="match_distribution")

# ---- Bar Chart: 100s and 50s ----
with col2:
    fig4 = go.Figure(data=[
        go.Bar(name='100s', x=formats, y=batting_df['100s']),
        go.Bar(name='50s', x=formats, y=batting_df['50s'])
    ])
    fig4.update_layout(
        title='Centuries and Fifties by Format',
        barmode='group',
        paper_bgcolor='rgba(0, 0, 0, 0.8)',
        plot_bgcolor='rgba(0, 0, 0, 0.7)',
        font=dict(color='white')
    )
    st.plotly_chart(fig4, use_container_width=True, key="hundreds_fifties")


# ---- Plotly Bar Charts for Additional Insights ----
st.subheader("Additional Visual Insights")
col1, col2 = st.columns(2)

with col1:
    fig2 = px.bar(
        batting_df,
        x='Format',
        y='Average',
        title='Batting Average by Format',
        text_auto=True,
        color='Format'
    )
    st.plotly_chart(fig2, use_container_width=True, key="bat_avg_chart")

with col2:
    fig3 = px.bar(
        batting_df,
        x='Format',
        y='Strike Rate',
        title='Strike Rate by Format',
        text_auto=True,
        color='Format'
    )
    st.plotly_chart(fig3, use_container_width=True, key="bat_sr_chart")







import plotly.graph_objects as go

# Line Chart for Batting Metrics
fig_batting_line = go.Figure()

# Add Average
fig_batting_line.add_trace(go.Scatter(
    x=batting_df['Format'],
    y=batting_df['Average'],
    mode='lines+markers',
    name='Batting Average',
    line=dict(width=3)
))

# Add Strike Rate
fig_batting_line.add_trace(go.Scatter(
    x=batting_df['Format'],
    y=batting_df['Strike Rate'],
    mode='lines+markers',
    name='Strike Rate',
    line=dict(width=3)
))

# Add Runs
fig_batting_line.add_trace(go.Scatter(
    x=batting_df['Format'],
    y=batting_df['Runs'],
    mode='lines+markers',
    name='Runs',
    line=dict(width=3)
))

# Style & layout
fig_batting_line.update_layout(
    title='Batting Metrics by Format',
    xaxis_title='Format',
    yaxis_title='Value',
    paper_bgcolor='rgba(0, 0, 0, 0.7)',
    plot_bgcolor='rgba(0, 0, 0, 0.5)',
    font=dict(color='white')
)

# Display in Streamlit
st.plotly_chart(fig_batting_line, use_container_width=True, key="batting_line")



















# ---- Bowling Visuals ----
st.subheader("Bowling Visual Insights")

# Bowling Average
# Row 1: Bowling Avg & Economy Rate
col1, col2 = st.columns(2)

with col1:
    fig_bowl_avg = px.bar(
        bowling_df,
        x='Format',
        y='Avg',
        title='Bowling Average by Format',
        text_auto=True,
        color='Format'
    )
    fig_bowl_avg.update_layout(
        paper_bgcolor='rgba(0, 0, 0, 0.7)',
        plot_bgcolor='rgba(0, 0, 0, 0.5)',
        font=dict(color='white')
    )
    st.plotly_chart(fig_bowl_avg, use_container_width=True, key="bowl_avg")

with col2:
    fig_bowl_eco = px.bar(
        bowling_df,
        x='Format',
        y='Economy',
        title='Economy Rate by Format',
        text_auto=True,
        color='Format'
    )
    fig_bowl_eco.update_layout(
        paper_bgcolor='rgba(0, 0, 0, 0.7)',
        plot_bgcolor='rgba(0, 0, 0, 0.5)',
        font=dict(color='white')
    )
    st.plotly_chart(fig_bowl_eco, use_container_width=True, key="bowl_eco")

# Row 2: Wickets & Hauls
col3, col4 = st.columns(2)

with col3:
    fig_wickets = px.bar(
        bowling_df,
        x='Format',
        y='Wickets',
        title='Wickets Taken by Format',
        text_auto=True,
        color='Format'
    )
    fig_wickets.update_layout(
        paper_bgcolor='rgba(0, 0, 0, 0.7)',
        plot_bgcolor='rgba(0, 0, 0, 0.5)',
        font=dict(color='white')
    )
    st.plotly_chart(fig_wickets, use_container_width=True, key="bowl_wkts")

with col4:
    fig_hauls = go.Figure(data=[
        go.Bar(name='5-wicket hauls', x=formats, y=bowling_df['5w']),
        go.Bar(name='10-wicket hauls', x=formats, y=bowling_df['10w'])
    ])
    fig_hauls.update_layout(
        title='5w and 10w Hauls by Format',
        barmode='group',
        paper_bgcolor='rgba(0, 0, 0, 0.7)',
        plot_bgcolor='rgba(0, 0, 0, 0.5)',
        font=dict(color='white')
    )
    st.plotly_chart(fig_hauls, use_container_width=True, key="bowl_hauls")













# Line Chart for Bowling Metrics
fig_bowling_line = go.Figure()

# Bowling Average
fig_bowling_line.add_trace(go.Scatter(
    x=bowling_df['Format'],
    y=bowling_df['Avg'],
    mode='lines+markers',
    name='Bowling Average',
    line=dict(width=3)
))

# Economy Rate
fig_bowling_line.add_trace(go.Scatter(
    x=bowling_df['Format'],
    y=bowling_df['Economy'],
    mode='lines+markers',
    name='Economy Rate',
    line=dict(width=3)
))

# Strike Rate


# Layout and style
fig_bowling_line.update_layout(
    title='Bowling Metrics by Format',
    xaxis_title='Format',
    yaxis_title='Value',
    paper_bgcolor='rgba(0, 0, 0, 0.7)',
    plot_bgcolor='rgba(0, 0, 0, 0.5)',
    font=dict(color='white')
)

# Display in Streamlit
st.plotly_chart(fig_bowling_line, use_container_width=True, key="bowling_line")