Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
21_22-J-02
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
21_22-J-02
21_22-J-02
Commits
0d725bfd
Commit
0d725bfd
authored
May 01, 2022
by
Chathurdi Vibhuda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat : BE grammer checker and blur detection
parent
8de4f1b1
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
331 additions
and
0 deletions
+331
-0
Presently/presently/users/grammerchecker&blur/__pycache__/.idea/.gitignore
...ly/users/grammerchecker&blur/__pycache__/.idea/.gitignore
+3
-0
Presently/presently/users/grammerchecker&blur/__pycache__/.idea/__pycache__.iml
...ers/grammerchecker&blur/__pycache__/.idea/__pycache__.iml
+11
-0
Presently/presently/users/grammerchecker&blur/__pycache__/.idea/inspectionProfiles/profiles_settings.xml
..._pycache__/.idea/inspectionProfiles/profiles_settings.xml
+6
-0
Presently/presently/users/grammerchecker&blur/__pycache__/.idea/misc.xml
...ntly/users/grammerchecker&blur/__pycache__/.idea/misc.xml
+7
-0
Presently/presently/users/grammerchecker&blur/__pycache__/.idea/modules.xml
...y/users/grammerchecker&blur/__pycache__/.idea/modules.xml
+8
-0
Presently/presently/users/grammerchecker&blur/__pycache__/Helpers.py
...resently/users/grammerchecker&blur/__pycache__/Helpers.py
+67
-0
Presently/presently/users/grammerchecker&blur/__pycache__/app.py
...ly/presently/users/grammerchecker&blur/__pycache__/app.py
+4
-0
Presently/presently/users/grammerchecker&blur/__pycache__/main.py
...y/presently/users/grammerchecker&blur/__pycache__/main.py
+143
-0
Presently/presently/users/grammerchecker&blur/__pycache__/templates/upload.html
...ers/grammerchecker&blur/__pycache__/templates/upload.html
+82
-0
No files found.
Presently/presently/users/grammerchecker&blur/__pycache__/.idea/.gitignore
0 → 100644
View file @
0d725bfd
# Default ignored files
/shelf/
/workspace.xml
Presently/presently/users/grammerchecker&blur/__pycache__/.idea/__pycache__.iml
0 → 100644
View file @
0d725bfd
<?xml version="1.0" encoding="UTF-8"?>
<module
type=
"PYTHON_MODULE"
version=
"4"
>
<component
name=
"NewModuleRootManager"
>
<content
url=
"file://$MODULE_DIR$"
/>
<orderEntry
type=
"jdk"
jdkName=
"Python 3.9 (mlenv)"
jdkType=
"Python SDK"
/>
<orderEntry
type=
"sourceFolder"
forTests=
"false"
/>
</component>
<component
name=
"TestRunnerService"
>
<option
name=
"PROJECT_TEST_RUNNER"
value=
"pytest"
/>
</component>
</module>
\ No newline at end of file
Presently/presently/users/grammerchecker&blur/__pycache__/.idea/inspectionProfiles/profiles_settings.xml
0 → 100644
View file @
0d725bfd
<component
name=
"InspectionProjectProfileManager"
>
<settings>
<option
name=
"USE_PROJECT_PROFILE"
value=
"false"
/>
<version
value=
"1.0"
/>
</settings>
</component>
\ No newline at end of file
Presently/presently/users/grammerchecker&blur/__pycache__/.idea/misc.xml
0 → 100644
View file @
0d725bfd
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<component
name=
"ProjectRootManager"
version=
"2"
project-jdk-name=
"Python 3.9 (mlenv)"
project-jdk-type=
"Python SDK"
/>
<component
name=
"PyCharmProfessionalAdvertiser"
>
<option
name=
"shown"
value=
"true"
/>
</component>
</project>
\ No newline at end of file
Presently/presently/users/grammerchecker&blur/__pycache__/.idea/modules.xml
0 → 100644
View file @
0d725bfd
<?xml version="1.0" encoding="UTF-8"?>
<project
version=
"4"
>
<component
name=
"ProjectModuleManager"
>
<modules>
<module
fileurl=
"file://$PROJECT_DIR$/.idea/__pycache__.iml"
filepath=
"$PROJECT_DIR$/.idea/__pycache__.iml"
/>
</modules>
</component>
</project>
\ No newline at end of file
Presently/presently/users/grammerchecker&blur/__pycache__/Helpers.py
0 → 100644
View file @
0d725bfd
import
cv2
import
numpy
as
np
class
Helpers
:
def
__init__
(
self
):
pass
def
resize
(
image
,
width
=
None
,
height
=
None
,
inter
=
cv2
.
INTER_AREA
):
dim
=
None
(
h
,
w
)
=
image
.
shape
[:
2
]
if
width
is
None
and
height
is
None
:
return
image
if
width
is
None
:
r
=
height
/
float
(
h
)
dim
=
(
int
(
w
*
r
),
height
)
else
:
r
=
width
/
float
(
w
)
dim
=
(
width
,
int
(
h
*
r
))
resized
=
cv2
.
resize
(
image
,
dim
,
interpolation
=
inter
)
return
resized
def
grab_contours
(
cnts
):
if
len
(
cnts
)
==
2
:
cnts
=
cnts
[
0
]
elif
len
(
cnts
)
==
3
:
cnts
=
cnts
[
1
]
else
:
raise
Exception
(
'The length of the contour must be 2 or 3.'
)
return
cnts
def
orders
(
pts
):
rect
=
np
.
zeros
((
4
,
2
),
dtype
=
"float32"
)
s
=
pts
.
sum
(
axis
=
1
)
rect
[
0
]
=
pts
[
np
.
argmin
(
s
)]
rect
[
2
]
=
pts
[
np
.
argmax
(
s
)]
diff
=
np
.
diff
(
pts
,
axis
=
1
)
rect
[
1
]
=
pts
[
np
.
argmin
(
diff
)]
rect
[
3
]
=
pts
[
np
.
argmax
(
diff
)]
return
rect
def
transform
(
image
,
pts
):
rect
=
Helpers
.
orders
(
pts
)
(
tl
,
tr
,
br
,
bl
)
=
rect
widthA
=
np
.
sqrt
(((
br
[
0
]
-
bl
[
0
])
**
2
)
+
((
br
[
1
]
-
bl
[
1
])
**
2
))
widthB
=
np
.
sqrt
(((
tr
[
0
]
-
tl
[
0
])
**
2
)
+
((
tr
[
1
]
-
tl
[
1
])
**
2
))
maxWidth
=
max
(
int
(
widthA
),
int
(
widthB
))
heightA
=
np
.
sqrt
(((
tr
[
0
]
-
br
[
0
])
**
2
)
+
((
tr
[
1
]
-
br
[
1
])
**
2
))
heightB
=
np
.
sqrt
(((
tl
[
0
]
-
bl
[
0
])
**
2
)
+
((
tl
[
1
]
-
bl
[
1
])
**
2
))
maxHeight
=
max
(
int
(
heightA
),
int
(
heightB
))
dst
=
np
.
array
([
[
0
,
0
],
[
maxWidth
-
1
,
0
],
[
maxWidth
-
1
,
maxHeight
-
1
],
[
0
,
maxHeight
-
1
]],
dtype
=
"float32"
)
M
=
cv2
.
getPerspectiveTransform
(
rect
,
dst
)
warped
=
cv2
.
warpPerspective
(
image
,
M
,
(
maxWidth
,
maxHeight
))
return
warped
Presently/presently/users/grammerchecker&blur/__pycache__/app.py
0 → 100644
View file @
0d725bfd
from
flask
import
Flask
app
=
Flask
(
__name__
)
app
.
secret_key
=
"secret key"
\ No newline at end of file
Presently/presently/users/grammerchecker&blur/__pycache__/main.py
0 → 100644
View file @
0d725bfd
from
tabnanny
import
check
from
app
import
app
from
flask
import
Flask
,
flash
,
request
,
redirect
,
render_template
,
jsonify
from
werkzeug.utils
import
secure_filename
import
cv2
import
numpy
as
np
import
io
from
PIL
import
Image
import
base64
from
Helpers
import
*
from
pptx
import
Presentation
from
pptx.enum.shapes
import
MSO_SHAPE_TYPE
import
language_tool_python
tool
=
language_tool_python
.
LanguageTool
(
'en-US'
)
text
=
"Your the best but their are allso good!"
matches
=
tool
.
check
(
text
)
print
(
len
(
matches
))
ALLOWED_EXTENSIONS
=
set
([
'ppt'
,
'pptx'
])
def
allowed_file
(
filename
):
return
'.'
in
filename
and
filename
.
rsplit
(
'.'
,
1
)[
1
]
.
lower
()
in
ALLOWED_EXTENSIONS
@
app
.
route
(
'/'
)
def
upload_form
():
return
render_template
(
'upload.html'
)
@
app
.
route
(
'/'
,
methods
=
[
'POST'
])
def
upload_image
():
global
i
,
n
,
images
,
text_runs
i
=
0
n
=
0
images
=
[]
text_runs
=
[]
f
=
request
.
files
.
getlist
(
"file[]"
)[
0
]
prs
=
Presentation
(
f
)
iter_picture_shapes
(
prs
)
get_text
(
prs
)
print
(
images
)
#print(images[1][0])
#base64img = getbase64_image(images[1][0])
page
=
[]
for
x
,
y
in
zip
(
text_runs
,
images
):
img1
=
[]
text1
=
[]
for
k
in
x
:
check
=
tool
.
check
(
k
)
if
len
(
check
)
>
0
:
text1
.
append
(
check
)
for
k
in
y
:
print
(
k
)
img
=
cv2
.
imread
(
k
)
gray
=
cv2
.
cvtColor
(
img
,
cv2
.
COLOR_BGR2GRAY
)
laplacian
=
cv2
.
Laplacian
(
gray
,
cv2
.
CV_64F
)
fm
=
laplacian
.
var
()
result
=
"Not Blurry"
if
fm
<
250
:
result
=
"Blurry"
print
(
result
,
fm
)
sharpness_value
=
"{:.0f}"
.
format
(
fm
)
message
=
[
result
,
sharpness_value
]
img1
.
append
([
message
,
getbase64_image
(
k
)])
if
(
len
(
img1
)
>
0
or
len
(
text1
)
>
0
):
page
.
append
([
img1
,
text1
])
print
(
len
(
page
))
return
render_template
(
'upload.html'
,
pages
=
page
)
n
=
0
i
=
0
filename
=
'test.pptx'
images
=
[]
page
=
[]
def
write_image
(
shape
):
global
n
,
i
image
=
shape
.
image
# ---get image "file" contents---
image_bytes
=
image
.
blob
# ---make up a name for the file, e.g. 'image.jpg'---
image_filename
=
'img/image{:03d}.{}'
.
format
(
n
,
image
.
ext
)
n
+=
1
# print(image_filename)
page
.
append
(
image_filename
)
with
open
(
image_filename
,
'wb'
)
as
f
:
f
.
write
(
image_bytes
)
def
visitor
(
shape
):
if
shape
.
shape_type
==
MSO_SHAPE_TYPE
.
GROUP
:
for
s
in
shape
.
shapes
:
visitor
(
s
)
if
shape
.
shape_type
==
MSO_SHAPE_TYPE
.
PICTURE
:
write_image
(
shape
)
def
iter_picture_shapes
(
prs
):
global
i
,
page
for
slide
in
prs
.
slides
:
page
=
[]
i
+=
1
# print(i)
for
shape
in
slide
.
shapes
:
visitor
(
shape
)
images
.
append
(
page
)
iter_picture_shapes
(
Presentation
(
filename
))
def
getbase64_image
(
image
):
img
=
img
=
cv2
.
imread
(
image
)
img
=
cv2
.
cvtColor
(
img
,
cv2
.
COLOR_BGR2RGB
)
file_object
=
io
.
BytesIO
()
img
=
Image
.
fromarray
(
Helpers
.
resize
(
img
,
width
=
500
))
img
.
save
(
file_object
,
'PNG'
)
return
"data:image/png;base64,"
+
base64
.
b64encode
(
file_object
.
getvalue
())
.
decode
(
'ascii'
)
text_runs
=
[]
prs
=
Presentation
(
filename
)
def
get_text
(
prs
):
for
slide
in
prs
.
slides
:
text1
=
[]
for
shape
in
slide
.
shapes
:
if
not
shape
.
has_text_frame
:
continue
for
paragraph
in
shape
.
text_frame
.
paragraphs
:
for
run
in
paragraph
.
runs
:
text1
.
append
(
run
.
text
)
text_runs
.
append
(
text1
)
get_text
(
prs
)
if
__name__
==
"__main__"
:
app
.
run
(
debug
=
True
)
print
(
images
)
Presently/presently/users/grammerchecker&blur/__pycache__/templates/upload.html
0 → 100644
View file @
0d725bfd
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<meta
charset=
"UTF-8"
>
<title>
Document
</title>
<link
rel=
"stylesheet"
href=
"https://stackpath.bootstrapcdn.com/bootstrap/4.5.1/css/bootstrap.min.css"
>
</head>
<body>
<div
class=
"card text-center mt-5 shadow-lg p-3 bg-white rounded"
style=
"width: 36rem;margin: auto;text-transform: uppercase;"
>
<h4
class=
"card-title mb-0"
>
Detecting Grammer
&
Blurred Photo
</h4>
<div>
{% if pages %}
{% for page in pages %}
<blockquote
class=
"blockquote"
>
<p>
page {{loop.index}}
</p>
</blockquote>
<div
class=
"card-body"
>
<div>
{% if page[0] %}
{% for image in page[0] %}
<div
class=
"alert alert-dark mb-0 mt-4"
>
{{ image[0][0] }}
<br>
Sharpness Value: {{ image[0][1] }}
</div>
<img
src=
"{{image[1]}}"
class=
"mt-0"
>
{% endfor %}
{% endif %}
</div>
<div
class=
"card-body"
>
<div>
{% if page[1] %}
{% for text in page[1] %}
{% if (text|length > 0) %}
<div
class=
"alert alert-dark mb-0 mt-4"
>
{% for t in text %}
<br>
{{ t.message }}
<br>
{{ t.sentence }}
<br>
{% for r in t.replacements %}
{{'Suggestion/Corrections : ' + r}}
{% endfor %}
<!-- {{ t.replacements }}-->
<br>
{% endfor %}
</div>
{% endif %}
{% endfor %}
{% endif %}
</div>
</div>
</div>
{% endfor %}
{% endif %}
</div>
<form
class=
"validated"
method=
"post"
action=
"/"
enctype=
"multipart/form-data"
>
<div
class=
"custom-file mb-3"
>
<input
type=
"file"
name=
"file[]"
class=
"custom-file-input"
id=
"document"
multiple
required
>
<label
class=
"custom-file-label"
for=
"document"
>
Choose Pptx...
</label>
<div
class=
"invalid-feedback"
>
Example invalid custom file feedback
</div>
</div>
<button
type=
"submit"
class=
"btn btn-block btn-danger"
>
EXTRACT
</button>
</form>
</div>
<script
src=
"https://code.jquery.com/jquery-3.5.1.slim.min.js"
></script>
<script
src=
"https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js"
></script>
<script
src=
"https://stackpath.bootstrapcdn.com/bootstrap/4.5.1/js/bootstrap.min.js"
></script>
</body>
</html>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment