-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
182 lines (147 loc) · 6.02 KB
/
main.py
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import array
import csv
import os
import re
import time
import cv2
import face_recognition
import lxml
import numpy as np
import pandas as pd
import requests
from bs4 import BeautifulSoup
from flask import Flask, render_template, request
from flask_wtf import FlaskForm
from werkzeug.datastructures import FileStorage
from werkzeug.utils import secure_filename
from wtforms import FileField, SubmitField
app = Flask(__name__, template_folder='template',
static_folder='template/assets')
app.config['UPLOAD_FOLDER'] = 'static'
app.config['SECRET_KEY'] = 'supersecretkey'
path = 'image'
images = []
classNames = []
myList = os.listdir(path)
for cl in myList:
curImg = cv2.imread(f'{path}/{cl}')
images.append(curImg)
classNames.append(os.path.splitext(cl)[0])
class uploadFileForm(FlaskForm):
file = FileField('File')
submit = SubmitField('Upload File')
encodeList = np.loadtxt('train.txt')
@app.route('/', methods=['GET', "POST"])
@app.route('/pt', methods=['GET', "POST"])
def home():
form = uploadFileForm()
if form.validate_on_submit():
file = form.file.data # First grab the file
file.save(os.path.join(os.path.abspath(os.path.dirname(__file__)),
app.config['UPLOAD_FOLDER'], secure_filename('test.jpg')))
imgtest = face_recognition.load_image_file('static/test.jpg')
imgtest = cv2.cvtColor(imgtest, cv2.COLOR_BGR2RGB)
encodetest = face_recognition.face_encodings(imgtest)[0]
matches = face_recognition.compare_faces(encodeList, encodetest)
faceDis = face_recognition.face_distance(encodeList, encodetest)
matchIndex = np.argmin(faceDis)
if matches[matchIndex]:
name = classNames[matchIndex+1].upper()
facedis = faceDis[matchIndex]
data = []
data.append(f'Player Name: {name}')
data.append(f'FaceDis: {facedis}')
print(name)
source = requests.get(f"https://www.google.com/search?q={name}%20cricbuzz").text
page = BeautifulSoup(source, "lxml")
page = page.find("div",class_="kCrYT")
link = page.find("a", href=re.compile(r"[/]([a-z]|[A-Z])\w+")).attrs["href"]
c = requests.get(link[7:]).text
cric = BeautifulSoup(c, "lxml")
profile = cric.find("div",id="playerProfile")
pc = profile.find("div",class_="cb-col cb-col-100 cb-bg-white")
#name country and image
name = pc.find("h1",class_="cb-font-40").text #1
country = pc.find("h3",class_="cb-font-18 text-gray").text #2
images = pc.findAll('img')
for image in images:
i = image['src'] #3
#personal information and rankings
personal =cric.find_all("div",class_="cb-col cb-col-60 cb-lst-itm-sm")
role = personal[2].text.strip() #5
icc = cric.find_all("div",class_="cb-col cb-col-25 cb-plyr-rank text-right")
tb = icc[0].text.strip() #6
ob = icc[1].text.strip() #7
twb = icc[2].text.strip() #8
tbw=icc[3].text.strip() #9
obw=icc[4].text.strip() #10
twbw=icc[5].text.strip() #11
#summary of the stata
summary = cric.find_all("div",class_="cb-plyr-tbl")
batting =summary[0]
bowling =summary[1]
cat = cric.find_all("td",class_="cb-col-8")
batstat = batting.find_all("td",class_="text-right")
#test
testmatches = batstat[0].text
testruns = batstat[3].text
tesths = batstat[4].text
testavg = batstat[5].text
testsr = batstat[7].text
test100 = batstat[8].text
test50 = batstat[10].text
#odii
odimatches = batstat[13].text
odiruns = batstat[16].text
odihs = batstat[17].text
odiavg = batstat[18].text
odisr = batstat[20].text
odi100 = batstat[21].text
odi50 = batstat[23].text
#t20
tmatches = batstat[26].text
truns = batstat[29].text
ths = batstat[30].text
tavg = batstat[31].text
tsr = batstat[33].text
t100 = batstat[34].text
t50 = batstat[36].text
bowstat = bowling.find_all("td",class_="text-right")
testballs = bowstat[2].text
testbruns = bowstat[3].text
testwickets = bowstat[4].text
testbbi = bowstat[5].text
testbbm = bowstat[6].text
testecon = bowstat[7].text
test5w = bowstat[10].text
odiballs = bowstat[14].text
odibruns = bowstat[15].text
odiwickets = bowstat[16].text
odibbi = bowstat[17].text
odiecon = bowstat[19].text
odi5w = bowstat[22].text
tballs = bowstat[26].text
tbruns = bowstat[27].text
twickets = bowstat[28].text
tbbi = bowstat[29].text
tecon = bowstat[31].text
t5w = bowstat[34].text
data.append(f'Name: {name}')
data.append(f'Country: {country}')
data.append(f'Role: {role}')
data.append("Matches Runs Highestscore Average StrikeRate 100s 50s")
data.append(f'Test Batting: {testmatches} {testruns} {tesths} {testavg} {testsr} {test100} {test50}')
data.append(f'ODI Batting: {odimatches} {odiruns} {odihs} {odiavg} {odisr} {odi100} {odi50}')
data.append(f'T20 Batting: {tmatches} {truns} {ths} {tavg} {tsr} {t100} {t50}')
data.append(f'Test Bowling: {testballs} {testbruns} {testwickets} {testbbi} {testbbm} {testecon} {test5w}')
data.append(f'ODI Bowling: {odiballs} {odibruns} {odiwickets} {odibbi} {odiecon} {odi5w}')
data.append(f'T20 Bowling: {tballs} {tbruns} {twickets} {tbbi} {tecon} {t5w}')
data.append(f'Test Batting Ranking: {tb}')
data.append(f'ODI Batting Ranking: {ob}')
data.append(f'T20 Batting Ranking: {twb}')
data.append(f'Test Bowling Ranking: {tbw}')
data.append(f'ODI Bowling Ranking: {obw}')
data.append(f'T20 Bowling Ranking: {twbw}')
return render_template('predict.html', data=data)
return render_template('upload.html', form=form)
app.run(host='0.0.0.0', port=8080)