Screenshot-to-code

emilwallner / Screenshot-to-code

利用神经网络将设计稿自动转换为静态网站代码,帮助开发者快速实现从视觉设计到前端页面的转化。

HTML AIGC Web 开发 开发工具 神经网络 设计稿转代码 前端自动化 AI 生成代码 静态网站

为什么值得看

编辑点评

这是AI辅助前端开发的经典开源项目,展示了计算机视觉与代码生成结合的可能性。适合设计师验证设计稿、开发者快速搭建原型或AI应用学习者研究。优点是思路直观、效果可视;缺点是生成的代码质量有限,复杂布局仍需手工调整,且项目维护活跃度一般。

Star 趋势

近 7 日
  • Star 总数16,515
  • 今日新增+0
  • 7 日增速0%
  • Fork1,544

同类项目

同场景 · AIGC / Web 开发 / 开发工具

项目文档

来自 GitHub README · master 分支

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

  • Bootstrap (The pre-trained model uses GRUs instead of LSTMs)
  • HTML

Acknowledgments

  • Thanks to IBM for donating computing power through their PowerAI platform
  • The code is largely influenced by Tony Beltramelli's pix2code paper. Code Paper
  • The structure and some of the functions are from Jason Brownlee's excellent tutorial

文档抓取自 GitHub 仓库 README,版权归原作者所有;已过滤徽章等噪音并经安全消毒后展示。