31K star!Screenshot to Code: 将截图翻译成代码的黑科技!

这篇文章介绍了ScreenshottoCode,一款能将屏幕截图自动转换为HTML/TailwindCSS、React、Vue或Bootstrap代码的GitHub项目。通过GPT-4Vision和DALL-E3,它极大简化了开发过程,但也存在精度问题。
摘要由CSDN通过智能技术生成

前言

当你看到你漂亮的网页,也想参考实现应该如何做呢?构思、设计、编码一系列的流程吗?现在的AI真是太神奇了,它让我们能够通过截图来翻译代码,再也不用费劲地手打了!

今天我们推荐的是一个让程序员们疯狂的 GitHub 项目,一键将图片的内容翻译从代码,在GitHub已超过31K Star的开源项目:Screenshot to Code 。

Screenshot to Code是什么?

这个简单的应用程序将屏幕截图转换为代码(HTML/Tailwind CSS、React、Vue 或 Bootstrap)。 它使用 GPT-4 Vision 生成代码,并使用 DALL-E 3 生成外观相似的图像。 您现在还可以输入 URL 来克隆实时网站!

借助GPT-4 Vision的突破性能力,Screenshot to Code 让人看到一种全新的开发模式正悄然到来。作为一名开发人员,这个工具让我非常惊讶。只需点击几下鼠标,它就能将以前密集的手动流程自动化。

以下是一个执行的示例,将泰勒·斯威夫特 Instagram 页面的屏幕截图转换为代码的过程:

在几秒钟内,屏幕截图到代码就可以以惊人的精度对页面设计进行建模。这是在开发过程中模拟设计的令人难以置信的资源。

安装 Screenshot to Code

Screenshot to Code 提供了在线使用环境,可以直接上传图片并执行:https://screenshottocode.com/

但是这个在线环境需要购买执行次数,或者绑定自己的OpenAI API key。这两件事我都不是很想做,所以还是看看自己安装部署吧。

目前来看主要有两种方式:源码启动和docker启动。

源码安装:

Screenshot to Code 由 React/Vite 开发前端和 FastAPI 开发后端。 同时需要一个能够访问 GPT-4 Vision 的 OpenAI API key。

首先启动后端(使用 Poetry 来管理依赖):

cd backend
echo "OPENAI_API_KEY=sk-your-key" > .env
poetry install
poetry shell
poetry run uvicorn main:app --reload --port 7001

启动前端部分:

cd frontend
yarn
yarn dev

启动完成后,在 http://localhost:5173 访问应用。

docker启动:

如果你的本地或服务器上已经有docker环境,那么可以直接使用docker来启动。

echo "OPENAI_API_KEY=sk-your-key" > .env
docker-compose up -d --build

同样的,启动完成后,在 http://localhost:5173 访问应用。

使用 Screenshot to Code

Screenshot to Code 目前支持转换的代码样式包括:HTML/Tailwind CSS、React、Vue和Bootstrap等,还有Ionic和SVG是bate状态。用户可以根据自己的需求选择适合自己的代码类型。无论你是前端新手还是经验丰富的开发者,都能够轻松地利用这个项目来快速生成所需的代码。

除了可以上传截图以外,还可以通弄过URL来获取截图,并自动生成代码。

但是这需要购买Screenshot to code 的次数,来获取API key才能使用。

随便截了个知乎首页的图,测试一下,电脑版的效果还挺不错,但是mobile的就差强人意了。

在代码中还可以向AI提出微调的要求,然后更新到代码中,一点点的优化最后的结果。

项目特点

优点

  • 它可以为程序员节省大量时间。
  • 它可以为您省钱。
  • 使用起来超级简单。

缺点

  • 它可能不准确。
  • 该工具不能替代人类程序员。

项目信息

  • 项目名称:Screenshot to Code
  • 在线体验:https://screenshottocode.com/
  • GitHub 链接:https://github.com/abi/screenshot-to-code
  • Star 数:31K+

Definition: A circular doubly linked list is a data structure that consists of a sequence of nodes, where each node contains a value, a reference to the next node, and a reference to the previous node in the sequence. The last node in the list points to the first node, creating a circular structure. Detailed study (explanation): A circular doubly linked list is similar to a doubly linked list, but with the added feature of being circular. This means that the last node in the list points back to the first node, creating a loop. This allows for more efficient traversal of the list in both directions, as well as easier implementation of certain algorithms. Applications: Circular doubly linked lists are useful in situations where a list needs to be traversed in both directions, such as in a music playlist where the user can skip forwards and backwards through songs. They can also be used in certain algorithms, such as the Josephus problem, where a group of people are arranged in a circle and every nth person is eliminated until only one person is left. Operations: Some common operations that can be performed on a circular doubly linked list include: 1. Insertion: Adding a new node to the list at a specific position. 2. Deletion: Removing a node from the list. 3. Traversal: Moving through the list in either direction, starting at a specific node. 4. Search: Finding a specific node in the list based on its value. Program implementation: A circular doubly linked list can be implemented using a Node class that contains the value, a reference to the next node, and a reference to the previous node. The list itself can be represented by a head node that points to the first node in the list. Java/C/C++ source code to perform operation: Here's some Java code that demonstrates how to perform various operations on a circular doubly linked list: ``` public class Node { int value; Node next; Node prev; public Node(int value) { this.value = value; this.next = null; this.prev = null; } } public class CircularDoublyLinkedList { Node head; public CircularDoublyLinkedList() { this.head = null; } public void insert(int value, int position) { Node newNode = new Node(value); if (head == null) { head = newNode; head.next = head; head.prev = head; } else { Node current = head; for (int i = 1; i < position; i++) { current = current.next; } newNode.next = current.next; newNode.prev = current; current.next.prev = newNode; current.next = newNode; } } public void delete(int value) { if (head == null) { return; } Node current = head; do { if (current.value == value) { current.prev.next = current.next; current.next.prev = current.prev; if (current == head) { head = current.next; } return; } current = current.next; } while (current != head); } public void traverseForward() { if (head == null) { return; } Node current = head; do { System.out.print(current.value + " "); current = current.next; } while (current != head); System.out.println(); } public void traverseBackward() { if (head == null) { return; } Node current = head.prev; do { System.out.print(current.value + " "); current = current.prev; } while (current != head.prev); System.out.println(); } public Node search(int value) { if (head == null) { return null; } Node current = head; do { if (current.value == value) { return current; } current = current.next; } while (current != head); return null; } } ``` Output-screenshot: Here's an example of how to use the above code to perform various operations on a circular doubly linked list: ``` CircularDoublyLinkedList list = new CircularDoublyLinkedList(); list.insert(1, 1); list.insert(2, 2); list.insert(3, 3); list.insert(4, 4); list.traverseForward(); // Output: 1 2 3 4 list.traverseBackward(); // Output: 4 3 2 1 list.delete(2); list.traverseForward(); // Output: 1 3 4 Node node = list.search(3); System.out.println(node.value); // Output: 3 ```
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值