Spaces:
Runtime error
Runtime error
Commit ·
4d0572e
1
Parent(s): ede10f8
models added with directory path changed
Browse filesFiles changed (20)
- .DS_Store
- __pycache__/app.cpython-38.pyc
- __pycache__/main_program.cpython-38.pyc
- app.py+4-4
- classes/.DS_Store
- classes/model/.DS_Store
- classes/model/__pycache__/pix2code2.cpython-38.pyc
- bin/.DS_Store → classes/model/bin/.DS_StoreRenamed
- bin/autoencoder.h5 → classes/model/bin/autoencoder.h5Renamed
- bin/autoencoder.json → classes/model/bin/autoencoder.jsonRenamed
- bin/meta_dataset.npy → classes/model/bin/meta_dataset.npyRenamed
- classes/model/bin/pix2code2.h5Added+3
- bin/pix2code2.json → classes/model/bin/pix2code2.jsonRenamed
- bin/words.vocab → classes/model/bin/words.vocabRenamed
- classes/model/pix2code2.py+61-56
- compiler/__pycache__/Compiler.cpython-38.pyc
- compiler/__pycache__/Utils.cpython-38.pyc
- data/.DS_Store
- data/output/input_image_from_interface.html+18-18
- main_program.py+11-12
19 unmodified lines20212223242526275 unmodified lines333435363738394019 unmodified linesnot approachable by those unfamiliar with programming, to drive these personas capable of designing and developingthe code bases and website structures we come up with an automated system. In this work, we showed and proposed thatmethods of deep learning and computer vision can be grasped to train a model that will automatically generate HTMLcode from a single input mockup image and try to build an end-to-end automated system with around 85% of accuracy fordeveloping the structures of a web pages.</p> """interface_article = """<div style='text-align: center;'> <br><br><a href='https://twitter.com/taneemishere'target='_blank'>Developed by Taneem Jan</a> </div>5 unmodified lines# a gradio interface to convert a image to HTML Codeinterface = gr.Interface(model_interface,inputs=gr.inputs.Image(),outputs=gr.outputs.Textbox(),title=interface_title,description=interface_description,article=interface_article19 unmodified lines20212223242526275 unmodified lines333435363738394019 unmodified linesnot approachable by those unfamiliar with programming, to drive these personas capable of designing and developingthe code bases and website structures we come up with an automated system. In this work, we showed and proposed thatmethods of deep learning and computer vision can be grasped to train a model that will automatically generate HTMLcode from a single input mockup image and try to build an end-to-end automated system with around 88% of accuracy fordeveloping the structures of web pages.</p> """interface_article = """<div style='text-align: center;'> <br><br><a href='https://twitter.com/taneemishere'target='_blank'>Developed by Taneem Jan</a> </div>5 unmodified lines# a gradio interface to convert a image to HTML Codeinterface = gr.Interface(model_interface,inputs='image',outputs='text',title=interface_title,description=interface_description,article=interface_article
123version https://git-lfs.github.com/spec/v1oid sha256:383193660ed3f29a378cec7afa7fb87ffbb938c7122c977fbb6bc3db8a0d8523size 565169576123452 unmodified lines8910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667__author__ = 'Ferdiand John Briones, attempt at pix2code2 through pretrained autoencoders'from keras.layers import Input, Dense, Dropout, RepeatVector, LSTM, concatenate, Flattenfrom keras.models import Sequential, Modelfrom tensorflow.keras.optimizers import RMSprop2 unmodified linesfrom .AModel import *from .autoencoder_image import *class pix2code2(AModel):def __init__(self, input_shape, output_size, output_path):AModel.__init__(self, input_shape, output_size, output_path)self.name = "pix2code2"visual_input = Input(shape=input_shape)#Load the pre-trained autoencoder modelautoencoder_model = autoencoder_image(input_shape, input_shape, output_path)autoencoder_model.load('autoencoder')autoencoder_model.model.load_weights('../bin/autoencoder.h5')#Get only the model up to the encoded parthidden_layer_model_freeze = Model(inputs=autoencoder_model.model.input, outputs=autoencoder_model.model.get_layer('encoded_layer').output)hidden_layer_input = hidden_layer_model_freeze(visual_input)#Additional layers before concatenationhidden_layer_model = Flatten()(hidden_layer_input)hidden_layer_model = Dense(1024, activation='relu')(hidden_layer_model)hidden_layer_model = Dropout(0.3)(hidden_layer_model)hidden_layer_model = Dense(1024, activation='relu')(hidden_layer_model)hidden_layer_model = Dropout(0.3)(hidden_layer_model)hidden_layer_result = RepeatVector(CONTEXT_LENGTH)(hidden_layer_model)#Make sure the loaded hidden_layer_model_freeze will no longer be updatedfor layer in hidden_layer_model_freeze.layers:layer.trainable = False#The same language model that of pix2code by Tony Beltramellilanguage_model = Sequential()language_model.add(LSTM(128, return_sequences=True, input_shape=(CONTEXT_LENGTH, output_size)))language_model.add(LSTM(128, return_sequences=True))textual_input = Input(shape=(CONTEXT_LENGTH, output_size))encoded_text = language_model(textual_input)decoder = concatenate([hidden_layer_result, encoded_text])decoder = LSTM(512, return_sequences=True)(decoder)decoder = LSTM(512, return_sequences=False)(decoder)decoder = Dense(output_size, activation='softmax')(decoder)self.model = Model(inputs=[visual_input, textual_input], outputs=decoder)optimizer = RMSprop(lr=0.0001, clipvalue=1.0)self.model.compile(loss='categorical_crossentropy', optimizer=optimizer)def fit_generator(self, generator, steps_per_epoch):self.model.summary()self.model.fit_generator(generator, steps_per_epoch=steps_per_epoch, epochs=EPOCHS, verbose=1)self.save()def predict(self, image, partial_caption):return self.model.predict([image, partial_caption], verbose=0)[0]def predict_batch(self, images, partial_captions):return self.model.predict([images, partial_captions], verbose=1)1234562 unmodified lines9101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172__author__ = 'Ferdiand John Briones, attempt at pix2code2 through pretrained autoencoders'import kerasfrom keras.layers import Input, Dense, Dropout, RepeatVector, LSTM, concatenate, Flattenfrom keras.models import Sequential, Modelfrom tensorflow.keras.optimizers import RMSprop2 unmodified linesfrom .AModel import *from .autoencoder_image import *class pix2code2(AModel):def __init__(self, input_shape, output_size, output_path):AModel.__init__(self, input_shape, output_size, output_path)self.name = "pix2code2"visual_input = Input(shape=input_shape)# Load the pre-trained autoencoder modelautoencoder_model = autoencoder_image(input_shape, input_shape, output_path)autoencoder_model.load('autoencoder')path_to_autoencoder = "bin/autoencoder.h5"autoencoder_model.model.load_weights(path_to_autoencoder)# Get only the model up to the encoded parthidden_layer_model_freeze = Model(inputs=autoencoder_model.model.input,outputs=autoencoder_model.model.get_layer('encoded_layer').output)hidden_layer_input = hidden_layer_model_freeze(visual_input)# Additional layers before concatenationhidden_layer_model = Flatten()(hidden_layer_input)hidden_layer_model = Dense(1024, activation='relu')(hidden_layer_model)hidden_layer_model = Dropout(0.3)(hidden_layer_model)hidden_layer_model = Dense(1024, activation='relu')(hidden_layer_model)hidden_layer_model = Dropout(0.3)(hidden_layer_model)hidden_layer_result = RepeatVector(CONTEXT_LENGTH)(hidden_layer_model)# Make sure the loaded hidden_layer_model_freeze will no longer be updatedfor layer in hidden_layer_model_freeze.layers:layer.trainable = False# The same language model that of pix2code by Tony Beltramellilanguage_model = Sequential()language_model.add(LSTM(128, return_sequences=True, input_shape=(CONTEXT_LENGTH, output_size)))language_model.add(LSTM(128, return_sequences=True))textual_input = Input(shape=(CONTEXT_LENGTH, output_size))encoded_text = language_model(textual_input)decoder = concatenate([hidden_layer_result, encoded_text])decoder = LSTM(512, return_sequences=True)(decoder)decoder = LSTM(512, return_sequences=False)(decoder)decoder = Dense(output_size, activation='softmax')(decoder)self.model = Model(inputs=[visual_input, textual_input], outputs=decoder)optimizer = RMSprop(lr=0.0001, clipvalue=1.0)self.model.compile(loss='categorical_crossentropy', optimizer=optimizer)def fit_generator(self, generator, steps_per_epoch):self.model.summary()self.model.fit_generator(generator, steps_per_epoch=steps_per_epoch, epochs=EPOCHS, verbose=1)self.save()def predict(self, image, partial_caption):return self.model.predict([image, partial_caption], verbose=0)[0]def predict_batch(self, images, partial_captions):return self.model.predict([images, partial_captions], verbose=1)
13 unmodified lines1415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616213 unmodified lines<div class="header clearfix"><nav><ul class="nav nav-pills pull-left"><li><a href="#">Pvzaon Nkj</a></li><li class="active"><a href="#">Qqkokd Dfa</a></li><li><a href="#">Dst Tivigk</a></li><li><a href="#">Kzszs Sdsm</a></li></ul></nav></div><div class="row"><div class="col-lg-6"><h4>Krifh</h4><p>bze iriu cg rwgnenhdrabsisonxvdonnfln lxzz t kbutnllqnu</p><a class="btn btn-success" href="#" role="button">Cekb Bvmdx</a></div><div class="col-lg-6"><h4>Bdjdl</h4><p>bvp lxiymey fqcie t qteeievmpxtythjihginxlqfhkpp zhb zm</p><a class="btn btn-success" href="#" role="button">Pjygtsu Ua</a></div></div><div class="row"><div class="col-lg-12"><h4>Yrqvw</h4><p>fcr cjn uhknvwmkaupf tncoimqmctcptmqrthfe tmwczxujpgnux</p><a class="btn btn-success" href="#" role="button">Mca Abrumv</a></div></div><div class="row"><div class="col-lg-3"><h4>Ulzox</h4><p>uqvuai bewmqmcoqowk uyfaecbm h rqy lyqvtus koebyvbsjiks</p><a class="btn btn-success" href="#" role="button">Klblo Ohtj</a></div><div class="col-lg-3"><h4>Jvidz</h4><p>lzjd pd sn wzlvrjprijuwhqeaalcjq lsppvcc xehbgnucnmm zwr</p><a class="btn btn-success" href="#" role="button">Wtg Gqvugc</a></div><div class="col-lg-3"><h4>Sudgx</h4><p>rtbilth uxeppfysvh t nuruz s abuhbkyzhtoaciir yqnjaqiyw</p><a class="btn btn-success" href="#" role="button">Thsq Qdcnh</a></div><div class="col-lg-3"><h4>Huzcm</h4><p>isfulr wmefbiy unuqmtuxhdtzyocwlncx r ozl pcyw kl bgbzaa</p><a class="btn btn-success" href="#" role="button">Vbeuieu Ux</a></div></div>13 unmodified lines1415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616213 unmodified lines<div class="header clearfix"><nav><ul class="nav nav-pills pull-left"><li><a href="#">Naezt Takq</a></li><li class="active"><a href="#">Ouynni Ium</a></li><li><a href="#">Ki Inamatv</a></li><li><a href="#">Cfhkpzd Dy</a></li></ul></nav></div><div class="row"><div class="col-lg-6"><h4>Brydw</h4><p>iynzkyecuztvhkhaxsrv ypkwtl axdw lwah yvkyjme ockdwfrq</p><a class="btn btn-success" href="#" role="button">Ltg Gllyyk</a></div><div class="col-lg-6"><h4>Rlite</h4><p>rvnzgydpvo zjlqdlsac slnlfetqd amvl pk utscjutbqpiej kn</p><a class="btn btn-success" href="#" role="button">Znwqceg Gq</a></div></div><div class="row"><div class="col-lg-12"><h4>Qwotz</h4><p>dwzuzqiqwzch tivhjaeryizwnqkcdtwk vxazt lyzyyef dq qyuqi</p><a class="btn btn-success" href="#" role="button">Mjg Gjuldz</a></div></div><div class="row"><div class="col-lg-3"><h4>Kaztt</h4><p>cldworfjqew fhly yqjbzf uomcekgpzv jnxribr u grmknqrhbo</p><a class="btn btn-success" href="#" role="button">Hcsdax Xpy</a></div><div class="col-lg-3"><h4>Esdux</h4><p>agpbejoeml pa wpgjv gnq pejvoai xeqmbrtedwhvzdnbs bcayj</p><a class="btn btn-success" href="#" role="button">Gjg Giqxte</a></div><div class="col-lg-3"><h4>Clrsc</h4><p>glnxwomntwdwdry gmjgnruxvfyclllpvv tcfnrsdsczinbfchzhhtb</p><a class="btn btn-success" href="#" role="button">Wys Swukwq</a></div><div class="col-lg-3"><h4>Gdwin</h4><p>qlenpxhdkbleome mnxxclztpghekvglzgzxxkpaxbdirnmldxcmcabq</p><a class="btn btn-success" href="#" role="button">Rfzykb Btu</a></div></div>
7 unmodified lines89101112131415161718192014 unmodified lines3536373839404142434445464748495051525354555626 unmodified lines8384858687887 unmodified linesfrom classes.model.pix2code2 import *def dsl_code_geneneration(input_image):trained_weights_path = "../bin"trained_model_name = "pix2code2"input_path = input_imageoutput_path = "../data/output/"search_method = "greedy"meta_dataset = np.load("{}/meta_dataset.npy".format(trained_weights_path), allow_pickle=True)input_shape = meta_dataset[0]output_size = meta_dataset[1]14 unmodified lineswith open("{}/{}.gui".format(output_path, file_name), 'w') as out_f:out_f.write(result.replace(START_TOKEN, "").replace(END_TOKEN, ""))return output_path, file_namedef compile_gui(outputpath, filename):from os.path import basenamefrom compclasses.Utils import Utilsfrom compclasses.Compiler import Compilerinput_path = (outputpath+filename)# remove the pathfile_ = os.path.basename(input_path)# remove the extensionfile_ = os.path.splitext(file_)[0]# add the extension of guifile_ = "../data/output/" + file_ + ".gui"input_file = file_26 unmodified linesdef main_method(input_image_from_interface):output_path, file_name = dsl_code_geneneration(input_image_from_interface)result = compile_gui(output_path, file_name)return result7 unmodified lines891011121314151617181914 unmodified lines3435363738394041424344454647484950515253545526 unmodified lines8283848586877 unmodified linesfrom classes.model.pix2code2 import *def dsl_code_generation(input_image):trained_weights_path = "classes/model/bin"trained_model_name = "pix2code2"input_path = input_imageoutput_path = "data/output/"search_method = "greedy"meta_dataset = np.load("{}/meta_dataset.npy".format(trained_weights_path), allow_pickle=True)input_shape = meta_dataset[0]output_size = meta_dataset[1]14 unmodified lineswith open("{}/{}.gui".format(output_path, file_name), 'w') as out_f:out_f.write(result.replace(START_TOKEN, "").replace(END_TOKEN, ""))return file_name, output_pathdef compile_gui(file_path, filename):from os.path import basenamefrom compiler.Utils import Utilsfrom compiler.Compiler import Compilerinput_path = (file_path+filename)# remove the pathfile_ = os.path.basename(input_path)# remove the extensionfile_ = os.path.splitext(file_)[0]# add the extension of guifile_ = "data/output/" + file_ + ".gui"input_file = file_26 unmodified linesdef main_method(input_image_from_interface):file_name, file_output_path= dsl_code_generation(input_image_from_interface)result = compile_gui(file_output_path, file_name)return result
.DS_Store
__pycache__/app.cpython-38.pyc
__pycache__/main_program.cpython-38.pyc
app.py+4-4
classes/.DS_Store
classes/model/.DS_Store
classes/model/__pycache__/pix2code2.cpython-38.pyc
bin/.DS_Store → classes/model/bin/.DS_StoreRenamed
bin/autoencoder.h5 → classes/model/bin/autoencoder.h5Renamed
bin/autoencoder.json → classes/model/bin/autoencoder.jsonRenamed
bin/meta_dataset.npy → classes/model/bin/meta_dataset.npyRenamed
classes/model/bin/pix2code2.h5Added+3
bin/pix2code2.json → classes/model/bin/pix2code2.jsonRenamed
bin/words.vocab → classes/model/bin/words.vocabRenamed
classes/model/pix2code2.py+61-56
compiler/__pycache__/Compiler.cpython-38.pyc
compiler/__pycache__/Utils.cpython-38.pyc
data/.DS_Store
data/output/input_image_from_interface.html+18-18
main_program.py+11-12