Spaces:
Sleeping
Sleeping
Incorporating intent understanding
Browse files- src/streamlit_app.py +36 -9
src/streamlit_app.py
CHANGED
|
@@ -3,7 +3,7 @@ import pandas as pd
|
|
| 3 |
import plotly.graph_objects as go
|
| 4 |
import plotly.express as px
|
| 5 |
import time
|
| 6 |
-
from agents import run_agents
|
| 7 |
from probability_engine import elo_probability
|
| 8 |
from data_loader import teams, team_map
|
| 9 |
|
|
@@ -22,10 +22,8 @@ venues = pd.read_csv("src/data/venue.csv")
|
|
| 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 |
# =========================
|
|
@@ -57,10 +55,18 @@ with left:
|
|
| 57 |
|
| 58 |
if query:
|
| 59 |
|
| 60 |
-
words = query.upper().split()
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
-
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
# Create impression of thinking and a spinning icon
|
| 66 |
# with st.spinner("Consulting the AI panel..."):
|
|
@@ -70,7 +76,29 @@ with left:
|
|
| 70 |
max_retries = 3
|
| 71 |
for attempt in range(max_retries):
|
| 72 |
try:
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
break
|
| 75 |
except Exception as e:
|
| 76 |
if "RateLimit" in str(e):
|
|
@@ -156,12 +184,11 @@ with right:
|
|
| 156 |
|
| 157 |
with tab2:
|
| 158 |
|
| 159 |
-
if query:
|
| 160 |
|
| 161 |
st.subheader("Win Probability")
|
| 162 |
|
| 163 |
# SPEEDOMETER
|
| 164 |
-
|
| 165 |
fig = go.Figure(go.Indicator(
|
| 166 |
mode="gauge+number",
|
| 167 |
value=probA*100,
|
|
|
|
| 3 |
import plotly.graph_objects as go
|
| 4 |
import plotly.express as px
|
| 5 |
import time
|
| 6 |
+
from agents import run_agents, detect_intent
|
| 7 |
from probability_engine import elo_probability
|
| 8 |
from data_loader import teams, team_map
|
| 9 |
|
|
|
|
| 22 |
# =========================
|
| 23 |
|
| 24 |
st.set_page_config(layout="wide")
|
|
|
|
| 25 |
st.title("🏏 Cricket World Cup AI Panel")
|
| 26 |
|
|
|
|
| 27 |
# =========================
|
| 28 |
# MAIN LAYOUT
|
| 29 |
# =========================
|
|
|
|
| 55 |
|
| 56 |
if query:
|
| 57 |
|
| 58 |
+
# words = query.upper().split()
|
| 59 |
+
|
| 60 |
+
# teamA = words[0]
|
| 61 |
+
# teamB = words[2]
|
| 62 |
|
| 63 |
+
intent_data = detect_intent(query)
|
| 64 |
+
|
| 65 |
+
intent = intent_data.get("intent")
|
| 66 |
+
teamA = intent_data.get("teamA")
|
| 67 |
+
teamB = intent_data.get("teamB")
|
| 68 |
+
group = intent_data.get("group")
|
| 69 |
+
venue = intent_data.get("venue")
|
| 70 |
|
| 71 |
# Create impression of thinking and a spinning icon
|
| 72 |
# with st.spinner("Consulting the AI panel..."):
|
|
|
|
| 76 |
max_retries = 3
|
| 77 |
for attempt in range(max_retries):
|
| 78 |
try:
|
| 79 |
+
if intent == "match_prediction":
|
| 80 |
+
if not teamA or not teamB:
|
| 81 |
+
st.error("Please provide two teams")
|
| 82 |
+
break
|
| 83 |
+
agent_outputs = run_agents("match", teamA, teamB)
|
| 84 |
+
probs = elo_probability(teamA, teamB)
|
| 85 |
+
probA = probs["probA"]
|
| 86 |
+
probB = probs["probB"]
|
| 87 |
+
elif intent == "group_progression":
|
| 88 |
+
if not group:
|
| 89 |
+
st.error("Please specify a group (e.g. Group D)")
|
| 90 |
+
break
|
| 91 |
+
agent_outputs = run_agents("group", group)
|
| 92 |
+
# no probability here
|
| 93 |
+
probA = None
|
| 94 |
+
probB = None
|
| 95 |
+
elif intent == "tournament_prediction":
|
| 96 |
+
agent_outputs = run_agents("tournament", intent_data.get("tournament_team"))
|
| 97 |
+
probA = None
|
| 98 |
+
probB = None
|
| 99 |
+
else:
|
| 100 |
+
st.error("Could not understand query")
|
| 101 |
+
break
|
| 102 |
break
|
| 103 |
except Exception as e:
|
| 104 |
if "RateLimit" in str(e):
|
|
|
|
| 184 |
|
| 185 |
with tab2:
|
| 186 |
|
| 187 |
+
if query and intent == "match_prediction":
|
| 188 |
|
| 189 |
st.subheader("Win Probability")
|
| 190 |
|
| 191 |
# SPEEDOMETER
|
|
|
|
| 192 |
fig = go.Figure(go.Indicator(
|
| 193 |
mode="gauge+number",
|
| 194 |
value=probA*100,
|