Spaces:
Sleeping
Sleeping
Updated app file
Browse files- src/streamlit_app.py +220 -29
src/streamlit_app.py
CHANGED
|
@@ -1,42 +1,233 @@
|
|
| 1 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
|
|
|
| 4 |
|
| 5 |
-
# --- Sidebar ---
|
| 6 |
-
st.sidebar.title("Controls")
|
| 7 |
-
theme = st.sidebar.selectbox("Theme (demo)", ["Light", "Dark"])
|
| 8 |
-
st.sidebar.info("This is the sidebar area.")
|
| 9 |
|
| 10 |
-
#
|
| 11 |
-
|
|
|
|
| 12 |
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
with left:
|
| 16 |
-
st.subheader("Chat Panel")
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
|
| 25 |
-
for msg in st.session_state.messages:
|
| 26 |
-
with st.chat_message(msg["role"]):
|
| 27 |
-
st.write(msg["content"])
|
| 28 |
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
if user_text:
|
| 32 |
-
st.session_state.messages.append({"role": "user", "content": user_text})
|
| 33 |
-
st.session_state.messages.append({"role": "assistant", "content": "hello"})
|
| 34 |
|
| 35 |
-
#
|
| 36 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
with right:
|
| 39 |
-
|
| 40 |
-
st.
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import plotly.graph_objects as go
|
| 4 |
+
import plotly.express as px
|
| 5 |
|
| 6 |
+
from agents import run_agents
|
| 7 |
+
from probability_engine import elo_probability
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
+
# =========================
|
| 11 |
+
# LOAD DATA
|
| 12 |
+
# =========================
|
| 13 |
|
| 14 |
+
batters = pd.read_csv("src/data/batters.csv")
|
| 15 |
+
bowlers = pd.read_csv("src/data/bowlers.csv")
|
| 16 |
+
teams = pd.read_csv("src/data/teams.csv")
|
| 17 |
+
venues = pd.read_csv("src/data/venue.csv")
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
# =========================
|
| 21 |
+
# PAGE CONFIG
|
| 22 |
+
# =========================
|
| 23 |
+
|
| 24 |
+
st.set_page_config(layout="wide")
|
| 25 |
+
|
| 26 |
+
st.title("π Cricket World Cup AI Panel")
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
# =========================
|
| 30 |
+
# MAIN LAYOUT
|
| 31 |
+
# =========================
|
| 32 |
+
|
| 33 |
+
left, right = st.columns([4,6])
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
# =========================
|
| 37 |
+
# LEFT SIDE CHAT
|
| 38 |
+
# =========================
|
| 39 |
|
| 40 |
with left:
|
|
|
|
| 41 |
|
| 42 |
+
st.header("Ask the AI Panel")
|
| 43 |
+
|
| 44 |
+
# Initialize variables
|
| 45 |
+
stats_output = ""
|
| 46 |
+
strategist_output = ""
|
| 47 |
+
chaos_output = ""
|
| 48 |
+
compere_output = ""
|
| 49 |
+
|
| 50 |
+
teamA = None
|
| 51 |
+
teamB = None
|
| 52 |
+
|
| 53 |
+
probA = None
|
| 54 |
+
probB = None
|
| 55 |
+
|
| 56 |
+
query = st.text_input("Example: IND vs AUS")
|
| 57 |
+
|
| 58 |
+
if query:
|
| 59 |
+
|
| 60 |
+
words = query.upper().split()
|
| 61 |
+
|
| 62 |
+
teamA = words[0]
|
| 63 |
+
teamB = words[2]
|
| 64 |
+
# with st.spinner("Consulting the AI panel..."):
|
| 65 |
+
|
| 66 |
+
agent_outputs = run_agents("match", teamA, teamB)
|
| 67 |
+
stats_output = agent_outputs["stats"]
|
| 68 |
+
strategist_output = agent_outputs["strategist"]
|
| 69 |
+
chaos_output = agent_outputs["chaos"]
|
| 70 |
+
compere_output = agent_outputs["compere"]
|
| 71 |
|
| 72 |
+
probs = elo_probability(teamA, teamB)
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
+
probA = probs["probA"]
|
| 75 |
+
probB = probs["probB"]
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
+
st.write("### Panel Verdict")
|
| 78 |
+
st.write(compere_output)
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
# =========================
|
| 82 |
+
# RIGHT SIDE TABS
|
| 83 |
+
# =========================
|
| 84 |
|
| 85 |
with right:
|
| 86 |
+
|
| 87 |
+
tab1, tab2 = st.tabs(["Agent Panel", "Insights"])
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
# =========================
|
| 91 |
+
# TAB 1 : AGENT PANEL
|
| 92 |
+
# =========================
|
| 93 |
+
|
| 94 |
+
with tab1:
|
| 95 |
+
|
| 96 |
+
st.subheader("Expert Debate Panel")
|
| 97 |
+
|
| 98 |
+
col1, col2 = st.columns(2)
|
| 99 |
+
col3, col4 = st.columns(2)
|
| 100 |
+
|
| 101 |
+
with col1:
|
| 102 |
+
st.markdown("### π Statistician")
|
| 103 |
+
st.write(stats_output)
|
| 104 |
+
|
| 105 |
+
with col2:
|
| 106 |
+
st.markdown("### π§ Strategist")
|
| 107 |
+
st.write(strategist_output)
|
| 108 |
+
|
| 109 |
+
with col3:
|
| 110 |
+
st.markdown("### π² Chaos Agent")
|
| 111 |
+
st.write(chaos_output)
|
| 112 |
+
|
| 113 |
+
with col4:
|
| 114 |
+
st.markdown("### π€ Compere")
|
| 115 |
+
# st.write(compere_output)
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
# =========================
|
| 119 |
+
# TAB 2 : INSIGHTS
|
| 120 |
+
# =========================
|
| 121 |
+
|
| 122 |
+
with tab2:
|
| 123 |
+
|
| 124 |
+
if query:
|
| 125 |
+
|
| 126 |
+
st.subheader("Win Probability")
|
| 127 |
+
|
| 128 |
+
# SPEEDOMETER
|
| 129 |
+
|
| 130 |
+
fig = go.Figure(go.Indicator(
|
| 131 |
+
mode="gauge+number",
|
| 132 |
+
value=probA*100,
|
| 133 |
+
title={'text': f"{teamA} Win Probability"},
|
| 134 |
+
gauge={
|
| 135 |
+
'axis': {'range': [0,100]},
|
| 136 |
+
'bar': {'color': "darkblue"},
|
| 137 |
+
'steps': [
|
| 138 |
+
{'range': [0,40], 'color': "red"},
|
| 139 |
+
{'range': [40,60], 'color': "orange"},
|
| 140 |
+
{'range': [60,100], 'color': "green"}
|
| 141 |
+
]
|
| 142 |
+
}
|
| 143 |
+
))
|
| 144 |
+
|
| 145 |
+
st.plotly_chart(fig, use_container_width=True)
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
# =========================
|
| 149 |
+
# BATTER COMPARISON
|
| 150 |
+
# =========================
|
| 151 |
+
|
| 152 |
+
st.subheader("Batting Comparison")
|
| 153 |
+
|
| 154 |
+
team_batters = batters[
|
| 155 |
+
batters["team"].isin([teamA, teamB])
|
| 156 |
+
]
|
| 157 |
+
|
| 158 |
+
fig2 = px.bar(
|
| 159 |
+
team_batters,
|
| 160 |
+
x="player",
|
| 161 |
+
y="strike_rate",
|
| 162 |
+
color="team",
|
| 163 |
+
title="Strike Rate Comparison"
|
| 164 |
+
)
|
| 165 |
+
|
| 166 |
+
st.plotly_chart(fig2, use_container_width=True)
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
# =========================
|
| 170 |
+
# BOWLING COMPARISON
|
| 171 |
+
# =========================
|
| 172 |
+
|
| 173 |
+
st.subheader("Bowling Comparison")
|
| 174 |
+
|
| 175 |
+
team_bowlers = bowlers[
|
| 176 |
+
bowlers["team"].isin([teamA, teamB])
|
| 177 |
+
]
|
| 178 |
+
|
| 179 |
+
fig3 = px.bar(
|
| 180 |
+
team_bowlers,
|
| 181 |
+
x="player",
|
| 182 |
+
y="economy",
|
| 183 |
+
color="team",
|
| 184 |
+
title="Economy Rate Comparison"
|
| 185 |
+
)
|
| 186 |
+
|
| 187 |
+
st.plotly_chart(fig3, use_container_width=True)
|
| 188 |
+
|
| 189 |
+
# ##########################################################################################
|
| 190 |
+
# ##########################################################################################
|
| 191 |
+
|
| 192 |
+
# import streamlit as st
|
| 193 |
+
|
| 194 |
+
# st.set_page_config(page_title="Hello Chat App", layout="wide")
|
| 195 |
+
|
| 196 |
+
# # --- Sidebar ---
|
| 197 |
+
# st.sidebar.title("Controls")
|
| 198 |
+
# theme = st.sidebar.selectbox("Theme (demo)", ["Light", "Dark"])
|
| 199 |
+
# st.sidebar.info("This is the sidebar area.")
|
| 200 |
+
|
| 201 |
+
# # --- Main layout panels ---
|
| 202 |
+
# st.title("Streamlit Chat Input Demo")
|
| 203 |
+
|
| 204 |
+
# left, right = st.columns([2, 1])
|
| 205 |
+
|
| 206 |
+
# with left:
|
| 207 |
+
# st.subheader("Chat Panel")
|
| 208 |
+
|
| 209 |
+
# # session state to store messages
|
| 210 |
+
# if "messages" not in st.session_state:
|
| 211 |
+
# st.session_state.messages = [
|
| 212 |
+
# {"role": "assistant", "content": "Hi! Type anything β I always say hello."}
|
| 213 |
+
# ]
|
| 214 |
+
|
| 215 |
+
# # display chat history
|
| 216 |
+
# for msg in st.session_state.messages:
|
| 217 |
+
# with st.chat_message(msg["role"]):
|
| 218 |
+
# st.write(msg["content"])
|
| 219 |
+
|
| 220 |
+
# # chat input
|
| 221 |
+
# user_text = st.chat_input("Enter free text here...")
|
| 222 |
+
# if user_text:
|
| 223 |
+
# st.session_state.messages.append({"role": "user", "content": user_text})
|
| 224 |
+
# st.session_state.messages.append({"role": "assistant", "content": "hello"})
|
| 225 |
+
|
| 226 |
+
# # re-render
|
| 227 |
+
# st.rerun()
|
| 228 |
+
|
| 229 |
+
# with right:
|
| 230 |
+
# st.subheader("Info Panel")
|
| 231 |
+
# st.write("Sidebar selection:", theme)
|
| 232 |
+
# st.write("Messages so far:", len(st.session_state.messages))
|
| 233 |
+
# st.success("Bot response is always: hello β
")
|