Skip to content

Commit

Permalink
added logic for graphing
Browse files Browse the repository at this point in the history
  • Loading branch information
Rishab committed Sep 8, 2019
1 parent 897a401 commit 28eb5cb
Show file tree
Hide file tree
Showing 5,300 changed files with 1,164,401 additions and 96,701 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
195 changes: 123 additions & 72 deletions .ipynb_checkpoints/test-checkpoint.ipynb

Large diffs are not rendered by default.

Binary file modified __pycache__/app.cpython-36.pyc
Binary file not shown.
Binary file added __pycache__/aws.cpython-36.pyc
Binary file not shown.
Binary file added __pycache__/frames.cpython-36.pyc
Binary file not shown.
Binary file added __pycache__/intelliment.cpython-36.pyc
Binary file not shown.
12 changes: 11 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import os
#import magic
from frames import frame_capture
from aws import build_dataset
import urllib.request
from flask import Flask, flash, request, redirect, render_template
from werkzeug.utils import secure_filename
from intelliment import generate_graphs

ALLOWED_EXTENSIONS = set(['mp4'])

Expand Down Expand Up @@ -35,9 +37,17 @@ def upload_file():
return redirect(request.url)
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
print(filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
flash('File successfully uploaded')
file_path = './static/upload/' + filename
frame_capture(file_path)
build_dataset()
generate_graphs()
return redirect('/')
else:
flash('Allowed file types are txt, pdf, png, jpg, jpeg, gif')
return redirect(request.url)


if __name__ == "__main__":
Expand Down
92 changes: 47 additions & 45 deletions aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,50 @@
import xlsxwriter
import os

with open('credentials.csv', 'r') as input:
next(input)
reader = csv.reader(input)
for line in reader:
access_key_id = line[0]
secret_access_key = line[1]

rekognition = boto3.client(
"rekognition", aws_access_key_id=access_key_id, aws_secret_access_key=secret_access_key, region_name='us-east-1')

frames = os.listdir('video_frames')

workbook = xlsxwriter.Workbook('sentigrade.xlsx')
worksheet = workbook.add_worksheet()

worksheet.write('A1', 'Second')
worksheet.write('B1', 'Image')
worksheet.write('C1', 'Emotion')
worksheet.write('D1', 'Confidence')

currRow = 2

for frame in frames:
print(frame)
photo = 'video_frames/' + frame
with open(photo, 'rb') as source_image:
source_bytes = source_image.read()
response = rekognition.detect_faces(
Image={'Bytes': source_bytes}, Attributes=['ALL'])

worksheet.write('A%d' % currRow, frame.replace('.jpg', ''))

maxEmotion = response['FaceDetails'][0]['Emotions']
maxNum = 0.0
for emotion in response['FaceDetails'][0]['Emotions']:
if emotion['Confidence'] > maxNum:
maxNum = emotion['Confidence']
maxEmotion = emotion['Type']

worksheet.write('B%d' % currRow, frame)
worksheet.write('C%d' % currRow, maxEmotion)
worksheet.write('D%d' % currRow, maxNum)
currRow += 1

workbook.close()

def build_dataset():
with open('credentials.csv', 'r') as input:
next(input)
reader = csv.reader(input)
for line in reader:
access_key_id = line[0]
secret_access_key = line[1]

rekognition = boto3.client(
"rekognition", aws_access_key_id=access_key_id, aws_secret_access_key=secret_access_key, region_name='us-east-1')

frames = os.listdir('video_frames')

workbook = xlsxwriter.Workbook('dataset.xlsx')
worksheet = workbook.add_worksheet()

worksheet.write('A1', 'Second')
worksheet.write('B1', 'Image')
worksheet.write('C1', 'Emotion')
worksheet.write('D1', 'Confidence')

currRow = 2

for frame in frames:
print(frame)
photo = 'video_frames/' + frame
with open(photo, 'rb') as source_image:
source_bytes = source_image.read()
response = rekognition.detect_faces(
Image={'Bytes': source_bytes}, Attributes=['ALL'])

worksheet.write('A%d' % currRow, frame.replace('.jpg', ''))

maxEmotion = response['FaceDetails'][0]['Emotions']
maxNum = 0.0
for emotion in response['FaceDetails'][0]['Emotions']:
if emotion['Confidence'] > maxNum:
maxNum = emotion['Confidence']
maxEmotion = emotion['Type']

worksheet.write('B%d' % currRow, frame)
worksheet.write('C%d' % currRow, maxEmotion)
worksheet.write('D%d' % currRow, maxNum)
currRow += 1

workbook.close()
Binary file added bin/__pycache__/runxlrd.cpython-36.pyc
Binary file not shown.
Loading

0 comments on commit 28eb5cb

Please sign in to comment.