Revert "Merge branch 'feat/it17535090' into 'develop'"

This reverts merge request !53
parent 6bea4fd1
<?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
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>
\ No newline at end of file
<?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
<?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
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
from flask import Flask
app = Flask(__name__)
app.secret_key = "secret key"
\ No newline at end of file
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)
<!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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment