Introduction
The exponential rise of IPL in India has correlatively resulted within the progress of fantasy cricket within the nation. In recent times, now we have seen increasingly individuals enjoying on platforms like Dream 11, My Circle, and many others. on daily basis. Dream11 is a fantasy sports activities app the place you may create your fantasy staff for sports activities like cricket, soccer, kabaddi, and many others. primarily based on real-life matches. When you construct your staff, you may be part of competitions and win each day money prizes. In these video games, for each single match, it’s a must to create an 11-player sports activities staff. The purpose is to play with this staff and earn most factors to win most rewards. On this article, I’ll present you methods to create a Dream 11 fantasy cricket team with which you’ll be able to win as much as Rs. 1 Crore in India, utilizing Python and AI. So let’s hit it off!
Guidelines and Constraints for Choosing the Dream 11 Staff
The staff you’ll create on Dream 11 can have 11 gamers out of twenty-two gamers. Out of those, a most of seven gamers could be from the identical staff in actual life. Your Dream11 can have completely different combos of gamers, however needs to be throughout the 100-credit cap and should fulfill the next staff choice standards:
Constructing Your Dream 11 Staff
As soon as you might be carried out together with your staff, now it’s time to pick your captain and vice-captain. On this article, for example, I’m going to create a staff for a match between Chennai Tremendous Kings and Punjab Kings.
We start by working 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):
attempt:
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):
attempt:
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:
attempt:
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:
attempt:
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 large cricket fan, and good with analysing match information.
"""
immediate = """
I'll present you batting & bowling information for 2 cricket matches.
Match 1 information offered between three backticks.
Match 2 information offered between separator ####.
Now, one staff from every of those two matches are enjoying tonight.
Your job is to analyse the 2 matches information.
And create a Fantasy staff for tonight's match between {m3_team1} & {m3_team2}.
This fantasy staff 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:
Here’s how to create your Dream11 fantasy cricket team using the above interface.
- 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.
- Select ‘Team Batting First’
Input the team that chose to bat first in that match.
- Select ‘Team Bowling’
Input the team that chose to bowl first in that match.
- 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.
- Select ‘Team Batting First’
Input the team that chose to bat first in that match.
- Select ‘Team Bowling’
Input the team that chose to bowl first in that match.
- Select ‘Teams Playing Today’
Choose the two teams who will be playing today’s fantasy match.
- Enter ‘GPT Model API’
Enter your GPT Model API or choose ‘gpt-3.5-turbo-1106’, if unsure.
- Click Submit
And with that final click, here is your dream 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