Skip to content

Commit

Permalink
Keras architecture
Browse files Browse the repository at this point in the history
  • Loading branch information
Dhvani Patel committed Jul 26, 2017
1 parent 217008c commit deb2b95
Show file tree
Hide file tree
Showing 16 changed files with 906 additions and 400 deletions.
Empty file added Untitled Document
Empty file.
Binary file modified __pycache__/check_pypy_syntax.cpython-35.pyc
Binary file not shown.
Binary file added __pycache__/test_file.pypy-41.pyc
Binary file not shown.
Binary file modified __pycache__/toCheck.pypy-41.pyc
Binary file not shown.
59 changes: 58 additions & 1 deletion check_pypy_syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def find_nth(haystack, needle, n):
# Main method
def checkPyPySyntax(src):
myFile = open("toCheck.py", "w")
myFile.write(src.decode())
myFile.write(src)
myFile.close()
proc = subprocess.Popen(['pypy', '-m', 'py_compile', 'toCheck.py'], stderr=subprocess.PIPE)
streamdata, err = proc.communicate()
Expand Down Expand Up @@ -89,3 +89,60 @@ def checkPyPySyntax(src):
os.remove("toCheck.py")
return [errorObj]


# Main method
def checkPyPySyntaxT(src):
myFile = open("toCheck.py", "w")
myFile.write(src.decode())
myFile.close()
proc = subprocess.Popen(['pypy', '-m', 'py_compile', 'toCheck.py'], stderr=subprocess.PIPE)
streamdata, err = proc.communicate()
rc = proc.returncode
if rc == 0:
# No errors, all good
if os.path.isfile("toCheck.py") == True:
os.remove("toCheck.py")
return None
else:
# Error, disect data for constructor
fileBegInd = find_nth(err, 'File ', 1)
fileEndInd = find_nth(err, ',', 1)
lineInd = find_nth(err, 'line ', 1)

nextLineInd = find_nth(err, '\n', 1)


add = err[lineInd+5:nextLineInd]
add = re.sub("[^0-9]", "", add.decode())
if(add == ''):
add = '-1'
line = int(add)

textInd = find_nth(err, ' ', 1)
temp2 = err[textInd+4:]


nextLineIndTemp = find_nth(temp2, ' ', 1)
textAfter = err[textInd+4:nextLineIndTemp+textInd+3]

fileName = err[fileBegInd+6:fileEndInd-1]

colon = ':'

textBeforeInd = err.rfind(colon.encode())
textBefore = err[textBeforeInd+2:]
textBefore = textBefore.strip()

colonTwo = ':'

text = textBefore + colon.encode() + textAfter

cutoffInd = find_nth(err, '^', 1)
errorname = err[cutoffInd+2:textBeforeInd]

errorObj = CompileError(fileName, line, None, None, text, errorname)
if os.path.isfile("toCheck.py") == True:
os.remove("toCheck.py")
return [errorObj]


Binary file modified check_pypy_syntax.pyc
Binary file not shown.
37 changes: 23 additions & 14 deletions cnn_hub.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright 2017 Dhvani Patel

from check_pypy_syntax import checkPyPySyntax
from check_pypy_syntax import checkPyPySyntaxT
from compile_error import CompileError
import sqlite3
import tokenize
Expand All @@ -18,29 +18,26 @@

# 87 VOCAB

def random_color():
rgbl=[randint(0, 255),randint(0, 9),randint(0, 9)]
random.shuffle(rgbl)
return tuple(rgbl)

def set_col_from_json(all_tokens):
with open('vocabulary_color.json') as data_file:
data = json.load(data_file)
#print (len(data["indexes"]))
indexed_tokens = []
newCols = []
for num in range(len(data["indexes"])):
add = random_color()
newCols.append(add)
newCols = random.sample(range(len(data["indexes"])), len(data["indexes"]))
print (newCols)
for tok in all_tokens:
print (tok)
#print (tok)
toCompare = tok.value
indexed_tokens.append(data["indexes"].index(toCompare))
print (len(data["colours"]))
print (len(data["indexes"]))
print (data["indexes"].index("INDENT"))
colours = []
print (indexed_tokens)
for inds in indexed_tokens:
colours.append(newCols[inds])
print (colours)
return colours

def open_closed_tokens(token):
Expand Down Expand Up @@ -183,10 +180,10 @@ def create(numFile):
#print "Fetching all rows..."
all_rows = c.fetchmany(size=2100)
conn.close()
toTest = checkPyPySyntax(all_rows[numFile][0])
toTest = checkPyPySyntaxT(all_rows[numFile][0])

if toTest == None:
#print all_rows[numFile][0]
print ((all_rows[numFile][0]).decode())
all_tokens = []
text = (all_rows[numFile][0]).decode('utf-8')
#print (type(text))
Expand Down Expand Up @@ -253,14 +250,26 @@ def create(numFile):
#print (len(allCols))
#print (allCols)
iterInd = 0
pixels = []
print (allCols)
for row in allCols:
for elem in row:
print(elem, end=' ')
print()
for lines in allCols:
getCols = lines
#inIterInd = 0
new = []
for cols in range(len(getCols)):
pix[cols, iterInd] = (getCols[cols][0], getCols[cols][1], getCols[cols][2])
pix[cols, iterInd] = getCols[cols]
new[cols] = getCols[cols]
#inInterInd += 1
pixels.append(new)
iterInd += 1
#pix[5,6] = (255,0,0)

print (pix[0, 0])

im.save("test.png", "PNG")

#print all_text
Expand All @@ -273,6 +282,6 @@ def create(numFile):


if __name__ == '__main__':
create(4)
create(2)
#for x in range(10):
#create(x)
Loading

0 comments on commit deb2b95

Please sign in to comment.