Commit 6e44faa1 authored by Manoj Kumar's avatar Manoj Kumar

Merge branch 'manoj_dev' of http://gitlab.sliit.lk/2020_077/2020_077 into manoj_dev

parents 4128d7dd 58be045d
......@@ -20,3 +20,4 @@ dataq/mask_rcnn_coco.h5
/reveng/output
*.pyc
dataq/utils.zip
/static/output
from werkzeug.utils import secure_filename
import requests
import shutil
from flask import send_file
from reveng.processInput import checkCommon, processInput
from flask import url_for,flash,Flask, render_template, request, redirect
from flask import url_for, flash, Flask, render_template, request, redirect
import json
import sys
import os
from flask_cors import CORS, cross_origin
REVENG_DIR = os.path.dirname(os.path.abspath(__file__))
TEMPLATE = os.path.join(REVENG_DIR, "\\templates")
......@@ -12,6 +16,7 @@ STATIC = os.path.join(REVENG_DIR, "\\static")
app = Flask(__name__)
app.config["DEBUG"] = True
cors = CORS(app)
@app.route('/test', methods=['GET'])
......@@ -19,7 +24,6 @@ def testApi():
return "<h1>The API is working</h1>"
# DATAQ
# route to redirect Home page
......@@ -35,37 +39,45 @@ def openCam():
return render_template('homePage.html')
# END DATAQ
# route to redirect About Us page
# route to redirect About Us page
@app.route('/about')
def about():
return render_template('about.html')
import requests
# route to redirect Sign Translation page
@app.route('/signToText')
def signToTextEngine():
return render_template('signToText.html')
# route to redirect Text Translation page
@app.route('/tts')
def textToSignEngine():
return render_template('textToSign.html')
# route to display GIF image to the user
@app.route('/tts/response/', methods=['POST'])
def response():
@app.route('/tts/get/<msg>', methods=['GET', 'POST'])
def response(msg):
clearoutputfolder()
message = request.get_json()
responseGIF = processInput(message['message'])
URL = 'http://localhost:3000/tts/upload'
PARAMS = {
"files":{
"file":{
"filename":responseGIF
}
}
}
requests.post(URL,PARAMS)
return send_file(responseGIF, mimetype='image/gif')
# message = request.get_json()
# responseGIF = processInput(message['message'])
print(msg)
responseGIF = processInput(msg)
# response = {
# "gifPath": responseGIF
# }
clearoutputfolder()
return responseGIF
# return send_file(responseGIF, mimetype='image/gif')
# clear the OUTPUT folder after displaying the GIF image
def clearoutputfolder():
folder = os.path.join(os.path.dirname(__file__), 'reveng\output')
folder = os.path.join(os.path.dirname(__file__), 'static\output')
for filename in os.listdir(folder):
file_path = os.path.join(folder, filename)
try:
......@@ -76,77 +88,13 @@ def clearoutputfolder():
except Exception as e:
print('Failed to delete %s. Reason: %s' % (file_path, e))
from werkzeug.utils import secure_filename
## upload image
UPLOAD_FOLDER = 'static/uploads/'
app.secret_key = "secret key"
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024
@app.route('/tts/upload', methods=['POST'])
def upload_image():
###
# This method is used upload the selected file to the exact folder
# after checking whether the extensions are matched.
# @return redirect to upload.html
###
if 'file' not in request.files:
flash('No file part')
return redirect(request.url)
file = request.files['file']
if file.filename == '':
flash('No image selected for uploading')
return redirect(request.url)
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
flash('Image successfully uploaded and displayed')
return render_template('upload.html', filename=filename)
else:
flash('Allowed image types are -> png, jpg, jpeg, gif')
return redirect(request.url)
@app.route('/tts/display/<filename>')
def display_image(filename):
###
# This method is used display the uploaded file back to the user
# @return display the file in the interface
###
return redirect(url_for('static', filename='uploads/' + filename), code=301)
ALLOWED_EXTENSIONS = set(['png', 'jpg', 'jpeg', 'gif'])
def allowed_file(filename):
###
# This method is used check the extension of selected file
# @return the extension to check whether it is allowed
###
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
# route to redirect Sign Translation page
@app.route('/tts')
def textToSignEngine():
return render_template('textToSign.html')
# route to redirect Contact Us page
@app.route('/contact')
@app.route('/contactUs')
def contactUs():
return render_template('contactUs.html')
# for testing purpose
@app.route('/signToText')
def signToTextEngine():
return render_template('signToText.html')
host = "localhost"
app.run(host=host, port=3000)
......
#from reveng.processInput import processInput
from reveng.processSentence import processCommonSentence
#from reveng.processWord import processWord
from reveng.processWord import processCommonWord
from reveng.getImages import getImagesCommonSentence
from reveng.getImages import getImagesCommonWord
from reveng.getImages import getImagesRareWord
......
###
# This file is used to create firbase configuration for the application
# Each application has unique firbase configuration.
# @author Amashi Bastiansz | IT17143950
# @version 1.0
# @since 2020-08-13
# @since 2020-08-13
###
import json
......@@ -54,3 +54,8 @@ def getStorageInstance():
###
return store
def getStorageBucket():
return bucket
......@@ -62,21 +62,29 @@ def getImagesForCommonWord(message):
# @return call to generateGIF() method with selected hand images
###
images = store.child().list_files()
sendingToGIF = []
imageRes = []
images = store.child().list_files()
for i in images:
if i.name.startswith(message) and len(i.name) > 8:
print("common image name =" + i.name)
imageRes.append(i)
returnArr = []
for word in message:
if i.name.startswith(word) and len(i.name) > 8:
print(i.name)
print("image name =" + i.name)
imageRes.append(i)
print(imageRes)
for i in imageRes:
url = i.generate_signed_url(datetime.timedelta(300), method='GET')
response = requests.get(url)
images = io.BytesIO(response.content)
img = pigm.open(images)
returnArr.append(img)
imagesfromFirebase = io.BytesIO(response.content)
img = pigm.open(imagesfromFirebase)
sendingToGIF.append(img)
return returnArr
print("Type of array ", type(sendingToGIF))
return generateGIF(sendingToGIF)
def getImagesForRareWord(message):
......
###
# This file is used to:
# generate a GIF image
# send the generated GIF to the folder
# delete the GIF from cache
# generate a GIF image
# send the generated GIF to the folder
# delete the GIF from cache
# @author Amashi Bastiansz | IT17143950
# @version 1.5
# @since 2020-10-01
# @since 2020-10-01
###
import imageio
......@@ -16,42 +16,62 @@ import random
import cv2
import PIL.Image as pigm
import PIL.GifImagePlugin as gifHandler
from gcloud.storage.blob import Blob
from reveng.firebaseConfig import getStorageInstance, getStorageBucket
PATH = os.path.dirname(os.path.abspath(__file__))
gifName = ''.join(random.choices(string.ascii_uppercase +
string.digits, k=15))
STATIC_PATH = os.getcwd() + '\\static'
STATIC_PATH = os.getcwd() + "\\static"
Blob.generate_signed_url
store = getStorageInstance()
bucket = getStorageBucket()
def generateGIF(images):
###
# This method is used to generate a path for the created GIF image
# This method is used to generate a path for the created GIF image
# @return the generated GIF path
###
gifPath = os.path.join(STATIC_PATH + "\\output\\" + gifName + '.gif')
gifName = ''.join(random.choices(string.ascii_uppercase +
string.digits, k=15))
blob = ''
gifPath = ''
blob = bucket.blob("output/"+gifName + ".gif")
gifPath = STATIC_PATH + "\\output\\" + gifName + ".gif"
imageio.mimwrite(gifPath, images, duration=0.5)
print(gifPath)
return gifPath
with open(gifPath, 'rb') as gifImage:
blob.upload_from_file(gifImage)
blob.make_public()
response = {
"gifName": gifName,
"gifLocalPath": gifPath,
"gifPublicUrl": blob.public_url
}
return response
def sendGIF():
###
# This method is used to send the generated GIF to the exact folder to store it
###
x = imageio.mimread(os.path.join(PATH + "\\output\\" + gifName + '.gif'))
return x
def deleteFromCache():
###
# This method is used to delete the generated GIF from cache after uploading it to
# This method is used to delete the generated GIF from cache after uploading it to
# the exact project folder
# @return call to generateGIF() method with selected hand images
###
os.remove(os.path.join(PATH + "\\output\\" + gifName + '.gif'))
......@@ -19,6 +19,7 @@ import PIL.Image as pigm
from reveng.firebaseConfig import getStorageInstance
from reveng.checkCommon import checkInJson
from reveng.processSentence import processCommonSentence
from reveng.processWord import processCommonWord
from reveng.getImages import getImagesForCommonWord, getImagesForRareWord
from reveng.gifMaker import generateGIF
......@@ -121,3 +122,36 @@ def processInput(message):
img = pigm.open(imagesfromFirebase)
sendingToGIF.append(img)
return generateGIF(sendingToGIF)
else:
if checkInCommonWord(message):
return processCommonSentence(message)
else:
imageArray = []
sendingToGIF = []
images = store.child().list_files()
for i in images:
for item in message.split(" "):
if checkInCommonWord(item):
if i.name.startswith(item):
print("image name =" + i.name)
imageArray.append(i)
break
else:
for letter in list(item):
print("Length ", len(i.name))
if i.name.startswith(letter) and len(i.name) < 8:
print("image name =" + i.name)
imageArray.append(i)
break
for i in imageArray:
url = i.generate_signed_url(
datetime.timedelta(300), method='GET')
response = requests.get(url)
imagesfromFirebase = io.BytesIO(response.content)
img = pigm.open(imagesfromFirebase)
sendingToGIF.append(img)
return generateGIF(sendingToGIF)
###
# This file is used to check a user-entered sentence with json file
# and return the relevant GIF image
# @author Amashi Bastiansz | IT17143950
# @version 2.0
# @since 2020-07-15
###
import json
import os
from reveng.getImages import getImagesForCommonWord
REVENG = os.path.dirname(os.path.abspath(__file__))
def processCommonWord(message):
###
# This method is used to process a sentence which has similar sentences in common.json file
# and to return the GIF
###
splitMessage = message.split(" ")
gif = getImagesForCommonWord(splitMessage)
return gif
......@@ -65,7 +65,7 @@
$.ajax({
url: "http://127.0.0.1:3000/tts/response/",
data: JSON.stringify({ message: message }),
method: "POST",
method: "GET",
contentType: "application/json",
success: function (message) {
var text = $("#textInput").val();
......
* {
margin: 0;
padding: 0;
border: 0;
outline: 0;
}
.chat {
width: 300px;
height: 500px;
background-image: url("http://cdn9.staztic.com/app/a/2063/2063481/whatsapp-wallpaper-pack-hd-600519-0-s-156x156.jpg");
background-size: cover;
background-position: center center;
position: absolute;
border: 5px solid #000;
border-radius: 20px;
overflow: hidden;
box-shadow: 0 0 20px #000;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
box-sizing: border-box;
}
.chat .messages {
position: absolute;
left: 0;
bottom: 60px;
height: auto;
width: 100%;
}
.chat .messages .message {
padding: 20px 10px;
width: 100%;
box-sizing: border-box;
}
.chat .messages .message .you,
.chat .messages .message .bot {
border-radius: 10px;
padding: 10px;
width: 75%;
position: relative;
}
.chat .messages .message .you img,
.chat .messages .message .bot img {
width: 100%;
border-radius: 10px;
display: block;
}
.chat .messages .message .you:before,
.chat .messages .message .bot:before {
padding: 5px;
border-radius: 5px;
position: absolute;
top: -15px;
font-weight: bold;
color: #fff;
font-size: 12px;
}
.chat .messages .message .you {
background: #2ecc71;
float: right;
}
.chat .messages .message .you:before {
content: "You:";
background-color: #2ecc71;
right: 10px;
}
.chat .messages .message .bot {
background-color: #3498db;
float: left;
}
.chat .messages .message .bot:before {
content: "Bot:";
background-color: #3498db;
left: 10px;
}
.chat .messages .message:after {
content: "";
clear: both;
display: table;
}
.chat .input {
position: absolute;
left: 0;
bottom: 0;
height: 60px;
width: 100%;
background: #ecf0f1;
}
.chat .input .text {
background-color: #fff;
border-radius: 20px;
height: 40px;
position: absolute;
top: 10px;
left: 10px;
width: 270px;
box-shadow: inset 0 0 5px #aaa;
line-height: 40px;
padding: 0 20px;
box-sizing: border-box;
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="static/styles/chatbot-test.css"/>
<script>
window.console = window.console || function(t) {};
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
<script>
if (document.location.search.match(/type=embed/gi)) {
window.parent.postMessage("resize", "*");
}
</script>
<script src="chrome-extension://mooikfkahbdckldjjndioackbalphokd/assets/prompt.js"></script>
</head>
<body translate="no" data-new-gr-c-s-check-loaded="14.990.0" data-gr-ext-installed="">
<div class="chat">
<div class="messages">
<div class="message">
<div class="bot">
Send something like "good morning " or "sorry"
</div>
</div>
</div>
<div class="input">
<form action="#" id="chat" method="post">
<input class="text" contenteditable="" placeholder="Type your message here...">
</form>
</div>
</div>
<script src="https://cpwebassets.codepen.io/assets/common stopExecutionOnTimeout-157cd5b220a5c80d4ff8e0e70ac069bffd87a61252088146915e8726e5d9f147.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script id="rendered-js">
(function() {
var app;
$(document).ready(function() {
return app.init();
});
app = {
//api_key: "dc6zaTOxFJmzC", // Public API key from giphy.com
init: function() {
return this.bind_events();
},
bind_events: function() {
return $(document).on("submit", "#chat", function(e) {
app.send_message();
return e.preventDefault();
});
},
send_message: function() {
var msg;
msg = $(".text").val().trim();
if (msg) {
$(".text").val("");
$(".messages").append("<div class='message'><div class='you'>" + msg + "</div></div>");
return this.check(msg);
}
},
check: function(msg) {
var keyword;
if (msg != null) {
return this.get_gif(msg);
} else {
return this.bot_post("Wrong syntax ''gif me keyword''.");
}
},
bot_post: function(msg) {
return $(".messages").append("<div class='message'><div class='bot'>" + msg + "</div></div>");
},
get_gif: function(keyword) {
console.log(keyword)
return $.get(`http://localhost:3000/tts/get/${keyword}` , function(data) {
var index;
console.log(data)
return app.bot_post("<img src='" + data.gifPublicUrl + "' alt='' />");
}
);
}
};
}).call(this);
</script>
</body>
</html>
\ No newline at end of file
......@@ -73,7 +73,7 @@
<a class="dropdown-item" href="tts">English to SSL Translator</a>
</div>
</li>
<li class="nav-item active">
<li class="nav-item">
<a class="nav-link" href="contactUs">Contact Us</a>
</li>
</ul>
......
......@@ -39,12 +39,22 @@
<link rel="shortcut icon" href="static/images/EasyTalkFavicon_v1.png" type="image/x-icon">
<link rel="icon" href="static/images/EasyTalkFavicon_v1.png" type="image/x-icon">
<link rel="stylesheet" href="static/styles/chatbot-test.css"/>
<script>window.console = window.console || function(t) {};</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
<script>
if (document.location.search.match(/type=embed/gi)) {
window.parent.postMessage("resize", "*");
}
</script>
<script src="chrome-extension://mooikfkahbdckldjjndioackbalphokd/assets/prompt.js"></script>
</head>
<body>
<!-- header -->
<header class="fixed-top">
<!-- navbar -->
<!--<header class="fixed-top">
<div class="navigation w-100">
<div class="container">
<nav class="navbar navbar-expand-lg navbar-dark p-0">
......@@ -80,58 +90,33 @@
</nav>
</div>
</div>
</header>
</header>-->
<!-- /header -->
<!-- page title -->
<section class="page-title-section overlay" data-background="static/images/backgrounds/page-title.jpg">
<div class="container">
<div class="row">
<div class="col-md-8">
<ul class="list-inline custom-breadcrumb">
<li class="list-inline-item"><a class="h2 text-primary font-secondary" href="tts">English to SSL Translator</a></li>
</ul>
<br/>
<p class="text-lighten">Now you can translate any English text to SSL only by entering it here!!</p>
</div>
</div>
</div>
</section>
<!-- /page title -->
<!-- Text Translator -->
<section class="section">
<div class="container">
<div class="row">
<div class="col-12">
<h2 class="section-title text-center" style="margin-top: -5%;">Let's Start!!</h2>
<div id="chatbox">
<p class="botText">
<span>Enter the sentence you need to translate into SSL</span>
</p>
</div>
<br/>
<form id="form" class="justify-content-center" method="POST">
<div class="form-row align-items-center">
<div class="col-auto" id="userInput">
<label class="sr-only" for="userTextInput">Enter Your Text</label>
<input type="text" class="form-control-mb-2" id="userTextInput" placeholder="Enter any text" style="height: 80%; width:100%" name="msg"/>
</div>
<div class="col-auto">
<button type="submit" class="btn btn-primary mb-2" id="userButtonInput" style="height: 75%;">Translate to Sign</button>
<div class="chat">
<div class="messages">
<div class="message">
<div class="bot">
Welcome to Text to Sign Language Translator!! Now you can enter any phrase you need to translate into sign language
<br/>
Make sure to enter phrase like "Good Morning" or "Sorry"
</div>
</div>
</form>
</div>
</div>
</div>
</section>
</div>
<div class="input">
<form action="#" id="chat" method="post">
<input class="text" contenteditable="" placeholder="Type your message here...">
</form>
</div>
</div>
<!-- /Text Translator -->
<!-- footer -->
<footer>
<!-- copyright -->
<!--<footer>
<div class="copyright py-4 bg-footer">
<div class="container">
<div class="row">
......@@ -154,7 +139,7 @@
</div>
</div>
</div>
</footer>
</footer>-->
<!-- /footer -->
<!-- jQuery -->
......@@ -173,38 +158,64 @@
<!-- Main Script -->
<script src="static/js/script.js"></script>
<script>
$("#userTextInput").keypress(function(e){
if(e.which == 13){
//getResponseSign();
}
});
$("userButtonInput").click(function(){
//getResponseSign();
});
$("#form").on("submit", function (e) {
var message = $("#userTextInput").val();
e.preventDefault();
$.ajax({
//url: "http://127.0.0.1:5000/tts/response/",
url: "http://localhost:3000/tts/response/",
data: JSON.stringify({ message: message }),
method: "POST",
contentType: "application/json",
success: function (message) {
var text = $("#userTextInput").val();
var userHtml = '<p class="userText"><span>' + text + "</span></p>";
$("#userTextInput").val("");
$("#chatbox").append(userHtml);
document
.getElementById("userInput")
.scrollIntoView({ block: "start", behavior: "smooth" });
},
<script src="https://cpwebassets.codepen.io/assets/common stopExecutionOnTimeout-157cd5b220a5c80d4ff8e0e70ac069bffd87a61252088146915e8726e5d9f147.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script id="rendered-js">
(function() {
var app;
$(document).ready(function() {
return app.init();
});
app = {
init: function() {
return this.bind_events();
},
bind_events: function() {
return $(document).on("submit", "#chat", function(e) {
app.send_message();
return e.preventDefault();
});
});
</script>
},
send_message: function() {
var msg;
msg = $(".text").val().trim();
if (msg) {
$(".text").val("");
$(".messages").append("<div class='message'><div class='you'>" + msg + "</div></div>");
return this.check(msg);
}
},
check: function(msg) {
var keyword;
if (msg != null) {
return this.get_gif(msg);
} else {
return this.bot_post("Wrong syntax ''gif me keyword''.");
}
},
bot_post: function(msg) {
return $(".messages").append("<div class='message'><div class='bot'>" + msg + "</div></div>");
},
get_gif: function(keyword) {
console.log(keyword)
return $.get(`http://localhost:3000/tts/get/${keyword}` , function(data) {
var index;
console.log(data)
return app.bot_post("<img src='" + data.gifPublicUrl + "' alt='' />");
});
}
};
}).call(this);
</script>
</body>
</html>
\ No newline at end of file
......@@ -11,6 +11,8 @@ import numpy as np
import os
import string
tensorflow.compat.v1.disable_eager_execution()
class Translation:
PATH = os.path.dirname(__file__)
......@@ -58,19 +60,22 @@ class Translation:
self.data[0] = normalized_image_array
# run the inference
print("Before model*****************")
prediction = self.model.predict(self.data)
print("After model*****************")
#print(prediction)
#print(prediction.shape)
#print(type(prediction))
#print(prediction[0, 2])
for alpha in range(26):
if prediction[0, alpha] >= 0.8:
#print(string.ascii_uppercase[alpha])
return string.ascii_uppercase[alpha]
#break
print(string.ascii_uppercase[alpha])
#return string.ascii_uppercase[alpha]
break
print("After Classification*****************")
# if os.path.exists(loc):
# os.remove(loc)
# else:
# print("The file does not exist")
# return
return
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