Spaces:
Sleeping
Sleeping
update UI
Browse files- src/streamlit_app.py +41 -19
src/streamlit_app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
import json
|
|
|
|
| 4 |
|
| 5 |
st.set_page_config(page_title="Cricket AI Studio", page_icon="π", layout="wide")
|
| 6 |
|
|
@@ -29,7 +30,7 @@ SAMPLE_RESPONSE = {
|
|
| 29 |
}
|
| 30 |
|
| 31 |
def run_analysis(query: str) -> dict:
|
| 32 |
-
# For now: return sample JSON but overwrite the query so
|
| 33 |
resp = dict(SAMPLE_RESPONSE)
|
| 34 |
resp["query"] = query
|
| 35 |
return resp
|
|
@@ -95,7 +96,7 @@ with left:
|
|
| 95 |
pick = team_a if prob["team_a_win_prob"] >= prob["team_b_win_prob"] else team_b
|
| 96 |
|
| 97 |
st.session_state.messages.append(
|
| 98 |
-
{"role": "assistant", "content": f"Prediction: **{pick}**. Win probability: **{team_a} {pa}%** vs **{team_b} {pb}%**.
|
| 99 |
)
|
| 100 |
st.rerun()
|
| 101 |
|
|
@@ -121,15 +122,13 @@ with left:
|
|
| 121 |
with right:
|
| 122 |
st.subheader("Agent Panel")
|
| 123 |
|
| 124 |
-
tab_agents, tab_graphs
|
| 125 |
|
| 126 |
if not st.session_state.last_result:
|
| 127 |
with tab_agents:
|
| 128 |
st.info("Run a query from the left chat to populate the agent panel.")
|
| 129 |
with tab_graphs:
|
| 130 |
st.info("Run a query to generate graphs.")
|
| 131 |
-
with tab_json:
|
| 132 |
-
st.info("Run a query to view the JSON.")
|
| 133 |
else:
|
| 134 |
res = st.session_state.last_result
|
| 135 |
prob = res["probability"]
|
|
@@ -138,26 +137,49 @@ with right:
|
|
| 138 |
team_b = prob["team_b"]
|
| 139 |
pa = prob["team_a_win_prob"]
|
| 140 |
pb = prob["team_b_win_prob"]
|
| 141 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
|
| 143 |
# ---- Agents tab (2x2 grid) ----
|
| 144 |
with tab_agents:
|
| 145 |
-
#
|
| 146 |
k1, k2, k3 = st.columns(3)
|
| 147 |
-
k1.metric("
|
| 148 |
-
k2.metric("
|
| 149 |
-
k3.metric("
|
| 150 |
|
| 151 |
st.divider()
|
| 152 |
|
| 153 |
-
agents = res["agents"]
|
| 154 |
-
|
| 155 |
-
def agent_card(title: str, subtitle: str, text: str):
|
| 156 |
-
with st.container(border=True):
|
| 157 |
-
st.markdown(f"### {title}")
|
| 158 |
-
st.caption(subtitle)
|
| 159 |
-
st.write(text)
|
| 160 |
-
|
| 161 |
r1 = st.columns(2, gap="large")
|
| 162 |
with r1[0]:
|
| 163 |
agent_card("1οΈβ£ Statistician Agent", "Uses Elo + rankings", agents.get("stats_agent", "β"))
|
|
@@ -186,7 +208,7 @@ with right:
|
|
| 186 |
|
| 187 |
# Batting chart (strike rate)
|
| 188 |
bat = pd.DataFrame(res.get("batting_chart", []))
|
| 189 |
-
st.markdown("#### Batting Strike Rate
|
| 190 |
if bat.empty:
|
| 191 |
st.info("No batting_chart data in JSON.")
|
| 192 |
else:
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
import json
|
| 4 |
+
import random
|
| 5 |
|
| 6 |
st.set_page_config(page_title="Cricket AI Studio", page_icon="π", layout="wide")
|
| 7 |
|
|
|
|
| 30 |
}
|
| 31 |
|
| 32 |
def run_analysis(query: str) -> dict:
|
| 33 |
+
# For now: return sample JSON but overwrite the query so chat reflects user input
|
| 34 |
resp = dict(SAMPLE_RESPONSE)
|
| 35 |
resp["query"] = query
|
| 36 |
return resp
|
|
|
|
| 96 |
pick = team_a if prob["team_a_win_prob"] >= prob["team_b_win_prob"] else team_b
|
| 97 |
|
| 98 |
st.session_state.messages.append(
|
| 99 |
+
{"role": "assistant", "content": f"Prediction: **{pick}**. Win probability: **{team_a} {pa}%** vs **{team_b} {pb}%**. Check Agents + Graphs β"}
|
| 100 |
)
|
| 101 |
st.rerun()
|
| 102 |
|
|
|
|
| 122 |
with right:
|
| 123 |
st.subheader("Agent Panel")
|
| 124 |
|
| 125 |
+
tab_agents, tab_graphs = st.tabs(["π€ Agents", "π Graphs"])
|
| 126 |
|
| 127 |
if not st.session_state.last_result:
|
| 128 |
with tab_agents:
|
| 129 |
st.info("Run a query from the left chat to populate the agent panel.")
|
| 130 |
with tab_graphs:
|
| 131 |
st.info("Run a query to generate graphs.")
|
|
|
|
|
|
|
| 132 |
else:
|
| 133 |
res = st.session_state.last_result
|
| 134 |
prob = res["probability"]
|
|
|
|
| 137 |
team_b = prob["team_b"]
|
| 138 |
pa = prob["team_a_win_prob"]
|
| 139 |
pb = prob["team_b_win_prob"]
|
| 140 |
+
pa_pct = int(pa * 100)
|
| 141 |
+
pb_pct = int(pb * 100)
|
| 142 |
+
|
| 143 |
+
fav = team_a if pa >= pb else team_b
|
| 144 |
+
dog = team_b if fav == team_a else team_a
|
| 145 |
+
fav_pct = max(pa_pct, pb_pct)
|
| 146 |
+
dog_pct = min(pa_pct, pb_pct)
|
| 147 |
+
|
| 148 |
+
agents = res.get("agents", {})
|
| 149 |
+
|
| 150 |
+
def random_agent_metrics():
|
| 151 |
+
"""
|
| 152 |
+
Randomly adds a compact metrics line to make each agent card feel richer.
|
| 153 |
+
We keep it consistent with the match probability from JSON, but vary presentation.
|
| 154 |
+
"""
|
| 155 |
+
variants = [
|
| 156 |
+
f"**Pick:** {fav} Β· **Win prob:** {fav_pct}% Β· **Alt:** {dog} {dog_pct}%",
|
| 157 |
+
f"**Fav:** {fav} ({fav_pct}%) Β· **Underdog:** {dog} ({dog_pct}%)",
|
| 158 |
+
f"**Outcome:** {fav} likely Β· **Confidence band:** {random.randint(max(55, fav_pct-10), min(95, fav_pct+6))}%",
|
| 159 |
+
]
|
| 160 |
+
return random.choice(variants)
|
| 161 |
+
|
| 162 |
+
def agent_card(title: str, subtitle: str, statement: str):
|
| 163 |
+
with st.container(border=True):
|
| 164 |
+
st.markdown(f"### {title}")
|
| 165 |
+
st.caption(subtitle)
|
| 166 |
+
|
| 167 |
+
# Agent statement from JSON
|
| 168 |
+
st.write(statement if statement else "β")
|
| 169 |
+
|
| 170 |
+
# Random additional metrics line
|
| 171 |
+
st.markdown(random_agent_metrics())
|
| 172 |
|
| 173 |
# ---- Agents tab (2x2 grid) ----
|
| 174 |
with tab_agents:
|
| 175 |
+
# Note: query not displayed at top (per requirement)
|
| 176 |
k1, k2, k3 = st.columns(3)
|
| 177 |
+
k1.metric("Favoured Team", fav)
|
| 178 |
+
k2.metric("Win Prob (fav)", f"{fav_pct}%")
|
| 179 |
+
k3.metric("Opponent", dog)
|
| 180 |
|
| 181 |
st.divider()
|
| 182 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 183 |
r1 = st.columns(2, gap="large")
|
| 184 |
with r1[0]:
|
| 185 |
agent_card("1οΈβ£ Statistician Agent", "Uses Elo + rankings", agents.get("stats_agent", "β"))
|
|
|
|
| 208 |
|
| 209 |
# Batting chart (strike rate)
|
| 210 |
bat = pd.DataFrame(res.get("batting_chart", []))
|
| 211 |
+
st.markdown("#### Batting Strike Rate")
|
| 212 |
if bat.empty:
|
| 213 |
st.info("No batting_chart data in JSON.")
|
| 214 |
else:
|