Commit b73e0f9b authored by Manoj Kumar's avatar Manoj Kumar

Merge branch 'amashi_dev' into 'master'

Added meaningful comments to the python files

See merge request !51
parents d5059986 15f99512
# 2020_077
# component for converting text input to SSL
# G.M.A.S. Bastiansz | IT17143950
import json,os
"""
This file is used as a main file for the user-inputs which have same words/sentences
appears in common.json file
@author Amashi Bastiansz | IT17143950
@version 1.2
@since 2020-07-30
"""
import json
import os
from reveng.processWord import processWord
from reveng.processSentence import processCommonSentence, processRareSentence
......@@ -6,8 +16,19 @@ from reveng.processSentence import processCommonSentence, processRareSentence
REVENG = os.path.dirname(os.path.abspath(__file__))
jsonPath = os.path.join(REVENG, 'common.json')
def checkInJson(message):
"""
# This method is used to create a GIF image for the user-input which is similar
with a sentence appears in common.json file
# Also, this method is used to create a GIF image for the user-input which is similar
with a word appears in common.json file
"""
# convert user-input into lowercase
message = message.lower()
with open(jsonPath) as jsonfile:
data = json.load(jsonfile)
sentences = data['sentences']
......@@ -19,10 +40,10 @@ def checkInJson(message):
alphabets = data['alphabet']
english_alphabet = alphabets['english']
# in common sentences
# compare the user-entered text with common sentences section in common.json file and create GIF
if message in english_common_sentences:
somegif = processCommonSentence(message)
return somegif
somegif = processCommonSentence(message)
return somegif
else:
commonwords = []
uncommonWords = []
......@@ -31,12 +52,11 @@ def checkInJson(message):
commonwords.append(item)
else:
uncommonWords.append(item)
#in common words
# compare the user-entered text with common words section in common.json file and create GIF
if message in englishwords:
somegif = processWord(message)
return somegif
else:
somegif = "no gif"
print("Call Rare methods here...")
import json, os, firebase_admin, datetime, requests,io
"""
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
"""
import json
import os
import firebase_admin
import datetime
import requests
import io
from firebase_admin import credentials
from firebase_admin import storage
import pyrebase
PATH = os.path.dirname(os.path.abspath(__file__))
JSON = os.path.join(PATH, 'credentials.json')
cred = credentials.Certificate(JSON)
app = firebase_admin.initialize_app(
cred,
{
'storageBucket': 'storage-9eed9.appspot.com',
},
name='storage')
cred,
{
'storageBucket': 'storage-9eed9.appspot.com',
},
name='storage')
bucket = storage.bucket(app=app)
config = {
......@@ -30,4 +47,10 @@ store = firebase.storage()
def getStorageInstance():
return store
\ No newline at end of file
"""
This method is used to redirect to the firebase cloud storage
@return Firebase Cloud Storage
"""
return store
import json, os, datetime, requests,io
from firebase_admin import storage
from reveng.firebaseConfig import getStorageInstance
"""
This file is used to fetch images of the hand signs from the system database
@author Amashi Bastiansz | IT17143950
@version 1.6
@since 2020-08-30
"""
import json
import os
import datetime
import requests
import io
import PIL.Image as pigm
from firebase_admin import storage
from reveng.firebaseConfig import getStorageInstance
from reveng.gifMaker import generateGIF
from gcloud.storage.blob import Blob
Blob.generate_signed_url
store = getStorageInstance()
def getImagesCommonWord(message):
"""
This method is used to select hand signs for user-entered text
These hand signs are for the words in the common_word section in the
common.json file
@return call to generateGIF() method with selected hand images
"""
images = store.child().list_files()
imageRes = []
for i in images:
if i.name.startswith(message):
print ("image name =" + i.name)
print("image name =" + i.name)
imageRes.append(i)
sendingToGIF =[]
sendingToGIF = []
for i in imageRes:
url = i.generate_signed_url(datetime.timedelta(300), method = 'GET')
url = i.generate_signed_url(datetime.timedelta(300), method='GET')
response = requests.get(url)
images = io.BytesIO(response.content)
img = pigm.open(images)
......@@ -27,16 +48,29 @@ def getImagesCommonWord(message):
return generateGIF(sendingToGIF)
def getImagesForCommonWord(message):
"""
This method is used to select hand signs for user-entered text
These hand signs are for the words in the common_word section in the
common.json file
This method is specifically made for the words which may have more than one hand sign
in the sign language (the words which are need multiple signs to show one verbal word)
@return call to generateGIF() method with selected hand images
"""
images = store.child().list_files()
imageRes = []
for i in images:
if i.name.startswith(message) and len(i.name) > 8:
print ("common image name =" + i.name)
print("common image name =" + i.name)
imageRes.append(i)
returnArr =[]
returnArr = []
for i in imageRes:
url = i.generate_signed_url(datetime.timedelta(300), method = 'GET')
url = i.generate_signed_url(datetime.timedelta(300), method='GET')
response = requests.get(url)
images = io.BytesIO(response.content)
img = pigm.open(images)
......@@ -44,16 +78,24 @@ def getImagesForCommonWord(message):
return returnArr
def getImagesForRareWord(message):
"""
This method is used to select hand signs for user-entered text
which is not appeared in common.json file
@return call to generateGIF() method with selected hand images
"""
images = store.child().list_files()
imageRes = []
for i in images:
if i.name.startswith(message) and len(i.name) < 8:
print ("rare image name =" + i.name)
print("rare image name =" + i.name)
imageRes.append(i)
returnArr =[]
returnArr = []
for i in imageRes:
url = i.generate_signed_url(datetime.timedelta(300), method = 'GET')
url = i.generate_signed_url(datetime.timedelta(300), method='GET')
response = requests.get(url)
images = io.BytesIO(response.content)
img = pigm.open(images)
......@@ -61,47 +103,61 @@ def getImagesForRareWord(message):
return returnArr
def getImagesRareWord(message):
"""
This method is used to select hand signs for user-entered text
which is not appeared in common.json file
@return call to generateGIF() method with selected hand images
"""
images = store.child().list_files()
imageRes = []
sendingToGIF = 0
for i in images:
if i.name == message + ".jpg":
print ("image name =" + i.name)
print("image name =" + i.name)
imageRes.append(i)
for i in imageRes:
url = i.generate_signed_url(datetime.timedelta(300), method = 'GET')
url = i.generate_signed_url(datetime.timedelta(300), method='GET')
response = requests.get(url)
images = io.BytesIO(response.content)
img = pigm.open(images)
sendingToGIF=img
sendingToGIF = img
return sendingToGIF
def getImagesCommonSentence(sentence):
sendingToGIF =[]
"""
This method is used to select hand signs for user-entered sentence
These hand signs are for the sentences in the common_sentence section in the
common.json file
@return call to generateGIF() method with selected hand images
"""
sendingToGIF = []
imageRes = []
images = store.child().list_files()
for i in images:
for word in sentence:
if i.name.startswith(word) and len(i.name) > 8:
print(i.name)
print ("image name =" + i.name)
imageRes.append(i)
print("image name =" + i.name)
imageRes.append(i)
print(imageRes)
for i in imageRes:
url = i.generate_signed_url(datetime.timedelta(300), method = 'GET')
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)
print("Type of array " , type(sendingToGIF))
return generateGIF(sendingToGIF)
print("Type of array ", type(sendingToGIF))
\ No newline at end of file
return generateGIF(sendingToGIF)
########################## To display the created GIF to user #############################
"""
This file is used to display the created GIF to user
This file is still at testing phase
@author Amashi Bastiansz | IT17143950
@version 1.2
@since 2020-10-01
"""
import os
import urllib.request
from flask import flash, request, redirect, url_for, Flask, render_template
from werkzeug.utils import secure_filename
from reveng.gifDisplayMain import main
# system will only allows to display files with below extensions
ALLOWED_EXTENSIONS = set(['png', 'jpg', 'jpeg', 'gif'])
app = Flask(__name__)
def allowed_file(filename):
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
"""
This method is used check the extension of created file
@return the extension to check whether it is allowed
"""
app = Flask(__name__)
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
@app.route('/', methods=['POST'])
def upload_image():
"""
This method is used check the extension of created file
@return the extension to check whether it is allowed
"""
if 'file' not in request.files:
flash('No file part')
return redirect(request.url)
......
import imageio,os, string , random,cv2
"""
This file is used to:
# 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
"""
import imageio
import os
import string
import random
import cv2
import PIL.Image as pigm
import PIL.GifImagePlugin as gifHandler
PATH = os.path.dirname(os.path.abspath(__file__))
gifName = ''.join(random.choices(string.ascii_uppercase +
string.digits, k = 15))
string.digits, k=15))
def generateGIF(images):
"""
This method is used to generate a path for the created GIF image
@return the generated GIF path
"""
gifPath = os.path.join(PATH + "\\output\\" + gifName + '.gif')
imageio.mimwrite(gifPath, images, duration = 0.5)
imageio.mimwrite(gifPath, images, duration=0.5)
print(gifPath)
return gifPath
# def generateGIFRare(images):
# RARE_GIF = imageio.mimwrite(os.path.join(PATH + "\\output\\" + gifName + '.gif'), images, duration = 0.5)
# return RARE_GIF
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():
os.remove(os.path.join(PATH + "\\output\\" + gifName + '.gif'))
\ No newline at end of file
"""
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'))
# from reveng.processWord import processWord
# from reveng.processSentence import processSentence
"""
This file is used to process the user-entered input
Through the methods in this file, the system will apply different Tokenization techniques
(in NLP) in order to make the input more identifiable
@author Amashi Bastiansz | IT17143950
@version 1.4
@since 2020-07-15
"""
import os
import json
import datetime
import requests
import io
import PIL.Image as pigm
from reveng.firebaseConfig import getStorageInstance
from reveng.checkCommon import checkInJson
from reveng.processSentence import processCommonSentence
from reveng.getImages import getImagesForCommonWord,getImagesForRareWord
from reveng.getImages import getImagesForCommonWord, getImagesForRareWord
from reveng.gifMaker import generateGIF
import os,json, datetime, requests,io
import PIL.Image as pigm
from reveng.firebaseConfig import getStorageInstance
# def processInput(message):
# msg_split = message.split(" ")
# print(msg_split)
# if(len(msg_split) <= 1):
# print("This is a word")
# processWord(message)
# return "Word"
# else:
# print("This is a sentence")
# processSentence(message)
# return "Sentence"
def checkCommon(message):
"""
This method is used to return the checkInJson() method in checkCommon.py file
"""
return checkInJson(message)
################## FIREBASE CONFIG ##########################
# initialize the variable, store to get the Firebase configuration
store = getStorageInstance()
###############################################################
REVENG = os.path.dirname(os.path.abspath(__file__))
jsonPath = os.path.join(REVENG, 'common.json')
def checkInCommonSentence(sentence):
"""
# This method is used to compare the user-input with common_sentence
section in common.json file
#If a similar setence appear in common_sentence section in common.json
file the method will return true
"""
with open(jsonPath) as jsonfile:
data = json.load(jsonfile)
sentences = data['sentences']
......@@ -42,7 +59,16 @@ def checkInCommonSentence(sentence):
else:
return False
def checkInCommonWord(word):
"""
This method is used to compare the user-input with common_words
section in common.json file
If a similar setence appear in common_word section in common.json
file the method will return true
"""
with open(jsonPath) as jsonfile:
data = json.load(jsonfile)
words = data['words']
......@@ -54,37 +80,42 @@ def checkInCommonWord(word):
else:
return False
def processInput(message):
"""
This method is used to send the fetched hand images to generateGIF()
method to create the final GIF image
"""
message = message.lower()
if len(message.split(" ")) >= 2:
if checkInCommonSentence(message):
return processCommonSentence(message)
else:
imageArray =[]
sendingToGIF =[]
images = store.child().list_files()
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)
print("image name =" + i.name)
imageArray.append(i)
break
else:
for letter in list(item):
print ("Length ", len(i.name))
print("Length ", len(i.name))
if i.name.startswith(letter) and len(i.name) < 9:
print ("image name =" + i.name)
print("image name =" + i.name)
imageArray.append(i)
break
for i in imageArray:
url = i.generate_signed_url(datetime.timedelta(300), method = 'GET')
url = i.generate_signed_url(
datetime.timedelta(300), method='GET')
response = requests.get(url)
imagesfromFirebase = io.BytesIO(response.content)
img = pigm.open(imagesfromFirebase)
......
"""
This file is used to check a user-entered sentence with json file
and return the relevant GIF image
import json,os
@author Amashi Bastiansz | IT17143950
@version 2.0
@since 2020-07-15
"""
import json
import os
from reveng.getImages import getImagesCommonSentence
REVENG = os.path.dirname(os.path.abspath(__file__))
#checking a sentence in json file
def processCommonSentence(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 = getImagesCommonSentence(splitMessage)
return gif
#checking a sentence in json file
def processRareSentence(message):
"""
This method is used to process a sentence which does not have similar sentences in common.json file
and to return the GIF
"""
splitMessage = message.split(" ")
gif = getImagesCommonSentence(splitMessage)
return gif
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