Screenshot-to-code README

The project's README from github.com/emilwallner/Screenshot-to-code. As one markdown file: README.md.


A detailed tutorial covering the code in this repository: Turning design mockups into code with deep learning.

Plug: 👉 Check out my 60-page guide, No ML Degree, on how to land a machine learning job without a degree.

The neural network is built in three iterations. Starting with a Hello World version, followed by the main neural network layers, and ending by training it to generalize.

The models are based on Tony Beltramelli's pix2code, and inspired by Airbnb's sketching interfaces, and Harvard's im2markup.

Note: only the Bootstrap version can generalize on new design mock-ups. It uses 16 domain-specific tokens which are translated into HTML/CSS. It has a 97% accuracy. The best model uses a GRU instead of an LSTM. This version can be trained on a few GPUs. The raw HTML version has potential to generalize, but is still unproven and requires a significant amount of GPUs to train. The current model is also trained on a homogeneous and small dataset, thus it's hard to tell how well it behaves on more complex layouts.

Dataset: https://github.com/tonybeltramelli/pix2code/tree/master/datasets

A quick overview of the process:

1) Give a design image to the trained neural network

Insert image

2) The neural network converts the image into HTML markup

3) Rendered output

Screenshot

Installation

FloydHub

Run on FloydHub

Click this button to open a Workspace on FloydHub where you will find the same environment and dataset used for the Bootstrap version. You can also find the trained models for testing.

Local

pip install keras tensorflow pillow h5py jupyter
git clone https://github.com/emilwallner/Screenshot-to-code.git
cd Screenshot-to-code/
jupyter notebook

Go do the desired notebook, files that end with '.ipynb'. To run the model, go to the menu then click on Cell > Run all

The final version, the Bootstrap version, is prepared with a small set to test run the model. If you want to try it with all the data, you need to download the data here: https://www.floydhub.com/emilwallner/datasets/imagetocode, and specify the correct dir_name.

Folder structure

  |  |-Bootstrap                           #The Bootstrap version
  |  |  |-compiler                         #A compiler to turn the tokens to HTML/CSS (by pix2code)
  |  |  |-resources											
  |  |  |  |-eval_light                    #10 test images and markup
  |  |-Hello_world                         #The Hello World version
  |  |-HTML                                #The HTML version
  |  |  |-Resources_for_index_file         #CSS,images and scripts to test index.html file
  |  |  |-html                             #HTML files to train it on
  |  |  |-images                           #Screenshots for training
  |-readme_images                          #Images for the readme page

Hello World

HTML

Bootstrap

Model weights

Acknowledgments

Screenshot-to-code (emilwallner/Screenshot-to-code)

Searching Database…

What is this?A neural network that turns a design mock-up image into the HTML markup of a static website — render that markup and you get the original design back.
Is this an app I can plug into my workflow, or more of a learning project?It's a learning project, not a production tool: Keras models in Jupyter notebooks, with a companion tutorial explaining how the code works.
How do I get it running?Two options: click the FloydHub button for a ready workspace with the environment, dataset and trained models, or open a local .ipynb notebook in Jupyter and run Cell > Run all.
What do I need on my machine to run it locally?A Jupyter setup is enough — the models are Keras notebooks. The Bootstrap version ships with a small test set; for the full data you have to download the dataset separately.
Can I feed it my own design mock-ups?Only the Bootstrap version generalizes to new design mock-ups, and it was trained on a small, homogeneous dataset — the README warns it's hard to say how it behaves on more complex layouts.
Where does the approach come from?The models are based on Tony Beltramelli's pix2code, and inspired by Airbnb's sketching interfaces and Harvard's im2markup. IBM donated the computing power through its PowerAI platform.
Which model architecture performs best?A GRU instead of an LSTM — the best model uses GRUs, and the pre-trained Bootstrap weights shipped in the repo are GRU-based.
Is there a walkthrough if I want to understand the code?Yes — the author wrote a detailed tutorial, 'Turning design mockups into code with deep learning', covering the code in this repository.
Size
50.4 MB
Stars
16.5K
Updated
CommitAug 16
Age
9y
Commits · 90 Days