Construct a Profitable Dream 11 Staff Utilizing Python and AI


Introduction

The exponential rise of IPL in India has correlatively resulted within the development of fantasy cricket within the nation. Lately, we now have seen increasingly more individuals enjoying on platforms like Dream 11, My Circle, and so forth. each day. Dream11 is a fantasy sports activities app the place you may create your fantasy crew for sports activities like cricket, soccer, kabaddi, and so forth. based mostly on real-life matches. When you construct your crew, you may be a part of competitions and win day by day money prizes. In these video games, for each single match, it’s a must to create an 11-player sports activities crew. The purpose is to play with this crew and earn most factors to win most rewards. On this article, I’ll present you the right way to create a Dream 11 fantasy cricket team with which you’ll win as much as Rs. 1 Crore in India, utilizing Python and AI. So let’s hit it off!

Build a Winning Dream 11 Team Using Python and AI

Guidelines and Constraints for Deciding on the Dream 11 Staff

The crew you’ll create on Dream 11 can have 11 gamers out of twenty-two gamers. Out of those, a most of seven gamers will be from the identical crew in actual life. Your Dream11 can have totally different mixtures of gamers, however needs to be inside the 100-credit cap and should fulfill the next crew choice standards:

Player selection rules and criteria

Constructing Your Dream 11 Staff

As soon as you’re completed together with your crew, now it’s time to pick your captain and vice-captain. On this article, for instance, I’m going to create a crew for a match between Chennai Tremendous Kings and Punjab Kings.

We start by operating the next code:

!pip set up openai==1.12.0

!pip set up gradio==4.19.0

from bs4 import BeautifulSoup
import pandas as pd
from openai import OpenAI
import gradio as gr
from google.colab import userdata

consumer = OpenAI(api_key=userdata.get('OPENAI_API_KEY'))

def pull_match_data(m_link):
    r = requests.get(m_link)
    soup = BeautifulSoup(r.textual content, 'html.parser')

    batting_columns = []
    for i in soup.find_all(class_='ds-w-full ds-table ds-table-md ds-table-auto ci-scorecard-table')[:1]:
        for j in i.find_all('th'):
            batting_columns.append(j.textual content)
    
    batting = []
    for i in soup.find_all(class_='ds-w-full ds-table ds-table-md ds-table-auto ci-scorecard-table')[:1]:
        rows = i.find_all('td', class_='ds-min-w-max')
        for i in vary(0, len(rows), 8):
            batter = []
            for j in vary(i, i+8):
                strive:
                    batter.append(rows[j].textual content)
                besides IndexError:
                    break
            batting.append(batter)
    innings1_batting = pd.DataFrame(batting, columns=batting_columns)

    batting_columns = []
    for i in soup.find_all(class_='ds-w-full ds-table ds-table-md ds-table-auto ci-scorecard-table')[1:2]:
        for j in i.find_all('th'):
            batting_columns.append(j.textual content)
    
    batting = []
    for i in soup.find_all(class_='ds-w-full ds-table ds-table-md ds-table-auto ci-scorecard-table')[1:2]:
        rows = i.find_all('td', class_='ds-min-w-max')
        for i in vary(0, len(rows), 8):
            batter = []
            for j in vary(i, i+8):
                strive:
                    batter.append(rows[j].textual content)
                besides IndexError:
                    break
            batting.append(batter)
    innings2_batting = pd.DataFrame(batting, columns=batting_columns)

    bowling_columns = []
    for i in soup.find_all(class_='ds-w-full ds-table ds-table-md ds-table-auto')[:1]:
        for j in i.find_all('th'):
            bowling_columns.append(j.textual content)
    
    bowling = []
    for i in soup.find_all(class_='ds-w-full ds-table ds-table-md ds-table-auto')[:1]:
        rows = i.find_all('td')
        bowler = []
        for i in vary(0, len(rows)):
            if len(bowler) < 11:
                if len(rows[i].textual content) < 20:
                    strive:
                        bowler.append(rows[i].textual content)
                    besides IndexError:
                        break
            else:
                bowling.append(bowler)
                bowler = []
                if len(rows[i].textual content) < 20:
                    bowler.append(rows[i].textual content)
    innings1_bowling = pd.DataFrame(bowling, columns=bowling_columns)

    bowling_columns = []
    for i in soup.find_all(class_='ds-w-full ds-table ds-table-md ds-table-auto')[1:2]:
        for j in i.find_all('th'):
            bowling_columns.append(j.textual content)
    
    bowling = []
    for i in soup.find_all(class_='ds-w-full ds-table ds-table-md ds-table-auto')[1:2]:
        rows = i.find_all('td')
        bowler = []
        for i in vary(0, len(rows)):
            if len(bowler) < 11:
                if len(rows[i].textual content) < 20:
                    strive:
                        bowler.append(rows[i].textual content)
                    besides IndexError:
                        break
            else:
                bowling.append(bowler)
                bowler = []
                if len(rows[i].textual content) < 20:
                    bowler.append(rows[i].textual content)
    innings2_bowling = pd.DataFrame(bowling, columns=bowling_columns)

    return innings1_batting, innings1_bowling, innings2_batting, innings2_bowling

def get_completion(m1_link, m1_batting_team, m1_bowling_team, m2_link, m2_batting_team, m2_bowling_team, m3_team1, m3_team2, mannequin="gpt-4-turbo-2024-04-09"):
    m1_innings1_batting, m1_innings1_bowling, m1_innings2_batting, m1_innings2_bowling = pull_match_data(m1_link)
    m2_innings1_batting, m2_innings1_bowling, m2_innings2_batting, m2_innings2_bowling = pull_match_data(m2_link)

    system_prompt = """
    You're a big cricket fan, and good with analysing match knowledge.
    """

    immediate = """
    I'll present you batting & bowling knowledge for 2 cricket matches.
    Match 1 knowledge supplied between three backticks.
    Match 2 knowledge supplied between separator ####.
    Now, one crew from every of those two matches are enjoying tonight.
    Your activity is to analyse the 2 matches knowledge.
    And create a Fantasy crew for tonight's match between {m3_team1} & {m3_team2}.
    This fantasy crew ought to have 11 gamers.

    ```

    Match 1: {m1_batting_team} vs {m1_bowling_team}
    Innings 1 >> {m1_batting_team} Batting
    {m1_innings1_batting}
    Innings 1 >> {m1_bowling_team} Bowling
    {m1_innings1_bowling}
    Innings 2 >> {m1_bowling_team} Batting
    {m1_innings2_batting}
    Innings 2 >> {m1_batting_team} Bowling
    {m1_innings2_bowling}
    ```

    ####

    Match 1: {m2_batting_team} vs {m2_bowling_team}
    Innings 1 >> {m2_batting_team} Batting
    {m2_innings1_batting}
    Innings 1 >> {m2_bowling_team} Bowling
    {m1_innings1_bowling}
    Innings 2 >> {m2_bowling_team} Batting
    {m2_innings2_batting}
    Innings 2 >> {m2_batting_team} Bowling
    {m2_innings2_bowling}
    ####
    """

    messages=[
        {"role": "system", "content": system_prompt},
        {"role": "user", "content": prompt}
    ]

    response = consumer.chat.completions.create(
        mannequin="gpt-4-turbo-2024-04-09",
        messages=messages,
        temperature=0
    )

    return response.selections[0].message.content material

iface = gr.Interface(
    fn=get_completion,
    inputs=[
        gr.Textbox(label="Team 1 Last Match Scorecard", lines=1

After running the code, you will get this interface:

Fantasy XI using AI

Here’s how to create your Dream11 fantasy cricket team using the above interface.

  1. Fill in ‘Team 1 Last Match Scorecard’

    Input the value of your first team’s scorecard from the last match. For reference, you can copy-paste this website link which contains the match between Chennai Super Kings and Sunrisers Hyderabad.

  2. Select ‘Team Batting First’

    Input the team that chose to bat first in that match.

  3. Select ‘Team Bowling’

    Input the team that chose to bowl first in that match.

  4. Add ‘Team 2 Last Match Scorecard’

    Input the value of your second team’s scorecard from the previous match. For reference, you can copy-paste this website link which contains the match between Kolkata Knight Riders and Punjab Kings.

  5. Select ‘Team Batting First’

    Input the team that chose to bat first in that match.

  6. Select ‘Team Bowling’

    Input the team that chose to bowl first in that match.

  7. Select ‘Teams Playing Today’

    Choose the two teams who will be playing today’s fantasy match.

  8. Enter ‘GPT Model API’

    Enter your GPT Model API or choose ‘gpt-3.5-turbo-1106’, if unsure.

  9. Click Submit

    Dream 11 fantasy cricket team

And with that final click, here is your dream team!

Your fantasy cricket dream 11 team

Conclusion

In this article, we explored the exciting possibility of using Python and AI to create a winning Dream11 team. By leveraging historical data and machine learning techniques, you can potentially gain an edge in selecting the best players and maximizing your points. Remember, while AI can be a powerful tool, factors like player form and pitch conditions also play a crucial role. So, for the ultimate Dream11 success, combine AI insights with your own cricketing knowledge. Now go ahead and take on the world of fantasy sports

Leave a Reply

Your email address will not be published. Required fields are marked *