File size: 3,468 Bytes
0a70d35
 
31e4cca
a79cecf
 
0a70d35
ed403d8
 
 
 
 
 
 
 
 
b40e248
0a70d35
b40e248
ed403d8
b40e248
 
a79cecf
93b411a
31e4cca
1e2285e
31e4cca
 
a79cecf
 
ed403d8
b40e248
 
ed403d8
 
31e4cca
b40e248
 
 
 
ed403d8
 
31e4cca
b40e248
 
 
a79cecf
ed403d8
 
31e4cca
 
 
a79cecf
31e4cca
ed403d8
31e4cca
ed403d8
31e4cca
 
 
ed403d8
31e4cca
ed403d8
b40e248
 
 
ed403d8
40f16c9
 
b40e248
40f16c9
b40e248
 
a79cecf
ed403d8
b40e248
a79cecf
0a70d35
ed403d8
b40e248
ed403d8
b40e248
 
3f0b250
846a791
 
b40e248
 
ed403d8
 
a79cecf
 
14f6e2e
31e4cca
ed403d8
 
 
 
14f6e2e
ed403d8
a79cecf
31e4cca
7152085
 
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
import streamlit as st
import os
from crewai import Agent, Task, Crew, LLM
from pydantic import BaseModel, Field
from typing import List

# 1. DATA STRUCTURE πŸ“
# This ensures the AI gives us a clean "story" instead of raw JSON code.
class MatchReport(BaseModel):
    match_title: str = Field(description="The formal title of the match.")
    player_of_the_match: str = Field(description="The standout performer and why.")
    deep_narrative: str = Field(description="A 3-paragraph story of the match events.")
    key_highlights: List[str] = Field(description="3-5 bullet points of critical moments.")

# 2. SETUP & SECRETS πŸ”‘
GROQ_API_KEY = os.environ.get("GROQ_API_KEY")

if not GROQ_API_KEY:
    st.error("Please set GROQ_API_KEY in your secrets.")
    st.stop()

# 3. LLM CONFIGURATION 🧠
# Updated LLM Configuration
cricket_llm = LLM(
    model="groq/llama-3.1-8b-instant",  # Updated supported ID
    api_key=GROQ_API_KEY
)

# 4. AGENT DEFINITIONS πŸ€–
# We define these FIRST so the tasks can find them.
scout = Agent(
    role="Cricket Match Scout",
    goal="Extract ball-by-ball data and Powerplay scores from {url}.",
    backstory="You are an expert at finding specific match facts.",
    llm=cricket_llm
)

analyst = Agent(
    role="Technical Match Analyst",
    goal="Identify momentum shifts and the Player of the Match.",
    backstory="You interpret data to find the 'why' behind the win.",
    llm=cricket_llm
)

writer = Agent(
    role="International Sports Journalist",
    goal="Write a deep, dramatic narration of the match.",
    backstory="You turn technical insights into a compelling story.",
    llm=cricket_llm
)

# 5. TASK DEFINITIONS πŸ“‹
scrape_task = Task(
    description="Analyze the commentary at {url}. Find key stats and partnerships.",
    agent=scout,
    expected_output="A list of match stats."
)

analyze_task = Task(
    description="Determine the turning points and the Player of the Match.",
    agent=analyst,
    expected_output="A technical summary of the game."
)

write_report_task = Task(
    description="Draft a deep narrative report. Focus on the drama and the Powerplay.",
    # We add this line to satisfy the Pydantic requirement:
    expected_output="A comprehensive match report following the MatchReport structure.",
    agent=writer,
    output_pydantic=MatchReport 
)

# 6. STREAMLIT UI πŸ–₯️
st.title("🏏 Cricket Intelligence")

url_input = st.text_input("Enter Match Commentary URL:")

if st.button("Generate Report"):
    if url_input:
        with st.spinner("Analyzing match data..."):
            match_crew = Crew(
                agents=[scout, analyst, writer],
                tasks=[scrape_task, analyze_task, write_report_task],
                verbose=True, # This helps us see the agents working in real-time
                max_rpm=2     # Limits the crew to 2 requests every 60 seconds
            )
            
            result = match_crew.kickoff(inputs={'url': url_input})
            report = result.pydantic
            
            st.header(report.match_title)
            st.subheader(f"πŸ† {report.player_of_the_match}")
            
            st.markdown("### ⚑ Highlights")
            for point in report.key_highlights:
                st.write(f"- {point}")
                
            st.divider()
            st.markdown("### πŸ“– Match Story")
            st.write(report.deep_narrative)
    else:
        st.warning("Please provide a URL.")