Mpavan45 commited on
Commit
ae42ed7
·
verified ·
1 Parent(s): 21dbbd1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -25
app.py CHANGED
@@ -2,6 +2,9 @@ import streamlit as st
2
  import pandas as pd
3
  import plotly.express as px
4
  import os
 
 
 
5
 
6
  # Streamlit App
7
  st.set_page_config(page_title="Cricket Player Stats Dashboard", layout="wide")
@@ -12,25 +15,9 @@ os.makedirs(data_folder, exist_ok=True)
12
 
13
  # File paths
14
  batting_path = "Batting_10_Teams_Final.csv"
15
- # os.path.join(data_folder, "batting.csv")
16
  bowling_path = "Bowling_10_Teams_Final.csv"
17
- # os.path.join(data_folder, "bowling.csv")
18
-
19
- # # Upload CSVs only if they are not already saved
20
- # if not (os.path.exists(batting_path) and os.path.exists(bowling_path)):
21
- # uploaded_batting = st.sidebar.file_uploader("Upload Batting CSV", type=["csv"], key="batting")
22
- # uploaded_bowling = st.sidebar.file_uploader("Upload Bowling CSV", type=["csv"], key="bowling")
23
-
24
- # if uploaded_batting and uploaded_bowling:
25
- # batting_df = pd.read_csv(uploaded_batting)
26
- # bowling_df = pd.read_csv(uploaded_bowling)
27
-
28
- # # Save the files permanently
29
- # batting_df.to_csv(batting_path, index=False)
30
- # bowling_df.to_csv(bowling_path, index=False)
31
- # st.success("CSV files saved successfully!")
32
- # else:
33
- # Load saved CSVs
34
  batting_df = pd.read_csv(batting_path)
35
  bowling_df = pd.read_csv(bowling_path)
36
 
@@ -50,10 +37,31 @@ player_bowling = bowling_df[(bowling_df['player_name'] == player) & (bowling_df[
50
 
51
  st.title(f"{player}'s Performance Dashboard")
52
 
53
- # Display player data
54
- st.subheader("Player Data")
 
 
 
 
 
 
 
 
 
 
 
 
55
 
56
- # Display only the first 16 columns
 
 
 
 
 
 
 
 
 
57
  if len(player_batting) > 0:
58
  st.write("### Batting Data")
59
  st.dataframe(player_batting.iloc[:min(17, len(player_batting)), :17])
@@ -66,9 +74,7 @@ if len(player_bowling) > 0:
66
  else:
67
  st.write("No bowling data available.")
68
 
69
-
70
-
71
- # Batting Visualization
72
  if not player_batting.empty:
73
  st.subheader("Batting Stats")
74
  col1, col2 = st.columns(2)
@@ -79,7 +85,7 @@ if not player_batting.empty:
79
  fig_bat_sr = px.line(player_batting, x='Format', y='SR', title='Strike Rate by Format')
80
  st.plotly_chart(fig_bat_sr, use_container_width=True)
81
 
82
- # Bowling Visualization
83
  if not player_bowling.empty:
84
  st.subheader("Bowling Stats")
85
  col3, col4 = st.columns(2)
 
2
  import pandas as pd
3
  import plotly.express as px
4
  import os
5
+ from langchain_google_genai import GoogleGenerativeAI
6
+ from langchain_core.prompts import ChatPromptTemplate
7
+ from langchain_core.output_parsers import StrOutputParser
8
 
9
  # Streamlit App
10
  st.set_page_config(page_title="Cricket Player Stats Dashboard", layout="wide")
 
15
 
16
  # File paths
17
  batting_path = "Batting_10_Teams_Final.csv"
 
18
  bowling_path = "Bowling_10_Teams_Final.csv"
19
+
20
+ # Load saved CSVs
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  batting_df = pd.read_csv(batting_path)
22
  bowling_df = pd.read_csv(bowling_path)
23
 
 
37
 
38
  st.title(f"{player}'s Performance Dashboard")
39
 
40
+ # Integrating LLMs using Gen-AI
41
+
42
+ # Loading API key and creating model
43
+ api_key = st.secrets.get('genai_key')
44
+ model = GoogleGenerativeAI(model="gemini-1.5-pro", google_api_key=api_key)
45
+
46
+ # Creating output parser to generate output
47
+ out_par = StrOutputParser()
48
+
49
+ # Creating prompt template
50
+ prompt = ChatPromptTemplate.from_messages([
51
+ ("system", "You are an AI cricket player information provider. You only provide information about players, not their stats."),
52
+ ("human", "{player_name}")
53
+ ])
54
 
55
+ # Creating chain
56
+ chain = prompt | model | out_par
57
+
58
+ # Query GenAI with the player's name
59
+ if st.button("Get Player Info"):
60
+ response = chain.invoke({"player_name": player})
61
+ st.subheader(f"Information about {player}")
62
+ st.write(response)
63
+
64
+ # ✅ Display only the first 16 columns
65
  if len(player_batting) > 0:
66
  st.write("### Batting Data")
67
  st.dataframe(player_batting.iloc[:min(17, len(player_batting)), :17])
 
74
  else:
75
  st.write("No bowling data available.")
76
 
77
+ # ✅ Batting Visualization
 
 
78
  if not player_batting.empty:
79
  st.subheader("Batting Stats")
80
  col1, col2 = st.columns(2)
 
85
  fig_bat_sr = px.line(player_batting, x='Format', y='SR', title='Strike Rate by Format')
86
  st.plotly_chart(fig_bat_sr, use_container_width=True)
87
 
88
+ # Bowling Visualization
89
  if not player_bowling.empty:
90
  st.subheader("Bowling Stats")
91
  col3, col4 = st.columns(2)