Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add anthropic key #360

Open
wants to merge 256 commits into
base: access-code
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
256 commits
Select commit Hold shift + click to select a range
7a3b366
Merge branch 'main' into main
kachbit Nov 29, 2023
14dbca8
fix conflict
kachbit Nov 29, 2023
7c3f06b
remove invalid code
kachbit Nov 29, 2023
ffbc89f
Merge branch 'main' into main
kachbit Nov 29, 2023
9bee5c7
Add prompt ionic support
dialmedu Nov 29, 2023
e13840d
Add Ionic support and Check Options
dialmedu Nov 29, 2023
9d68505
add prompt Ionic support
dialmedu Nov 29, 2023
7e504eb
add select UI Component and check options
dialmedu Nov 29, 2023
13888db
update URL to prod URL
abi Nov 29, 2023
af2fa8d
update onboarding note
abi Nov 29, 2023
562eee8
don't show onboarding note when access code is set
abi Nov 29, 2023
5c3fc7d
add email support when access code is set
abi Nov 29, 2023
9d9038f
add open graph tags
abi Nov 29, 2023
f4ecafa
Merge branch 'main' into main
kachbit Nov 30, 2023
b730ea3
Update Troubleshooting.md
abi Nov 30, 2023
1f08d71
Update Troubleshooting.md
abi Nov 30, 2023
ea10e19
Merge branch 'main' into pr/115
abi Nov 30, 2023
514688a
Merge branch 'main' of https://github.com/kachbit/screenshot-to-code …
abi Nov 30, 2023
b98bcb6
make settings modal not too big
abi Nov 30, 2023
226af5b
Merge pull request #115 from kachbit/main
abi Nov 30, 2023
339f073
Merge branch 'main' into pr/62
abi Nov 30, 2023
d9264a2
improve copy
abi Nov 30, 2023
0c532e5
don't show OpenAI Base URL setting on hosted version
abi Nov 30, 2023
fa6f579
fix issue with openAiBaseURL not being set
abi Nov 30, 2023
572dedb
fix typo
abi Nov 30, 2023
aae7c0e
fix type annotation
abi Nov 30, 2023
7a76621
Disable user-specified OpenAI Base URL in prod
abi Nov 30, 2023
5e6b889
Merge pull request #62 from Nothing1024/main
abi Nov 30, 2023
0fd6d74
add note for "Code Editor" theme
abi Nov 30, 2023
45a6432
Merge branch 'main' into pr/122
abi Nov 30, 2023
f51e70d
redo how output settings is configured
abi Nov 30, 2023
414d83c
catch prompt assembly error
abi Nov 30, 2023
dc28bd5
fix and add unit test
abi Nov 30, 2023
a5a834e
Merge pull request #139 from abi/ionic-changes
abi Nov 30, 2023
fcd305d
Update README.md
abi Nov 30, 2023
29ce6db
Update README.md
pranshugupta54 Dec 2, 2023
6849026
Merge pull request #158 from pranshugupta54/patch-1
abi Dec 2, 2023
3c90e16
Update UrlInputSection.tsx
pranshugupta54 Dec 3, 2023
f39bd28
remove comment
abi Dec 3, 2023
3e34c40
update libraries
abi Dec 3, 2023
0cc2c78
move websocket close to fix memory leak
abi Dec 3, 2023
a98b9d8
close OpenAI client
abi Dec 3, 2023
23aa6eb
tweak
abi Dec 4, 2023
273aa12
Merge pull request #160 from pranshugupta54/patch-2
abi Dec 4, 2023
96d45cf
add default backend home route so people know it's running correctly
abi Dec 4, 2023
26447ce
handle openai.AuthenticationError
abi Dec 4, 2023
e324051
handle model not found error better
abi Dec 4, 2023
70094ea
handle openai.RateLimitError
abi Dec 4, 2023
30e6b07
add list of logos
abi Dec 5, 2023
d487a73
Update README.md
abi Dec 6, 2023
2ba2a79
move AccessCodeSection to a separate component
abi Dec 6, 2023
c275e94
show credit usage to the user
abi Dec 6, 2023
0698af8
Merge branch 'main' of https://github.com/abi/screenshot-to-code
abi Dec 6, 2023
f010103
return failure reason to front-end
abi Dec 6, 2023
91934ec
add note about OpenAI API
abi Dec 6, 2023
328b75c
update status
abi Dec 6, 2023
f216146
initial history implementation
abi Dec 6, 2023
8a48c6d
add TODO
abi Dec 6, 2023
75198cf
allow viewing older versions
abi Dec 6, 2023
3d16d78
improve look of history display
abi Dec 6, 2023
8008513
handle coding state correctly
abi Dec 6, 2023
c1d6236
minor fix
abi Dec 6, 2023
286549f
track current version
abi Dec 6, 2023
a5e7dcd
correctly extract history for an update
abi Dec 6, 2023
79e36c9
move files around
abi Dec 7, 2023
97d6513
add some tests for history utils
abi Dec 7, 2023
eff532b
update test data
abi Dec 7, 2023
f5ddb77
make history forward chronology and have non-changing indices to refe…
abi Dec 7, 2023
0e8eef4
add parent for each item in history
abi Dec 7, 2023
874afc1
fix bug and show prompt
abi Dec 7, 2023
dd0f3b7
fix errors
abi Dec 7, 2023
2457a3f
update name
abi Dec 7, 2023
52adb46
move files
abi Dec 7, 2023
a559cd3
update to extract history tree with parent indices
abi Dec 7, 2023
0301f24
fix up pretty printing
abi Dec 7, 2023
b45e9de
clean up
abi Dec 7, 2023
2f53540
fix bug
abi Dec 7, 2023
889935d
Merge pull request #169 from abi/history
abi Dec 7, 2023
dc65f09
Update README.md
abi Dec 7, 2023
b3b478d
add hover card to show full prompt
abi Dec 7, 2023
8675d28
fix typescript and show badge of type of edit
abi Dec 7, 2023
3bd2321
nit: comment fix
abi Dec 7, 2023
edfafa2
Fix parameter type for generateCode
AlexLloyd0 Dec 8, 2023
4abee41
Remove redundant comment
AlexLloyd0 Dec 8, 2023
c0e68db
remove WIP GeneratedCodeConfig
AlexLloyd0 Dec 8, 2023
68a8d27
improve tests and catch history tree generation errors better
abi Dec 8, 2023
6a28ee2
strictly type python backend
abi Dec 9, 2023
435402b
split main.py into appropriate routes files
abi Dec 9, 2023
52fee9e
initial implementation of importing from code
abi Dec 10, 2023
e8e3d4c
make user set the stack when importing code
abi Dec 10, 2023
dcb9543
update prompts for all stack combos of imported code
abi Dec 10, 2023
356dd42
re-org files and improve tests
abi Dec 10, 2023
dd65a6e
add tests for the new prompts
abi Dec 10, 2023
bc64da7
Merge pull request #177 from abi/import-from-code
abi Dec 10, 2023
6385c50
Create design-docs.md
abi Dec 10, 2023
28db0a6
Update README.md
abi Dec 11, 2023
7edea28
Merge branch 'main' into pr/170
abi Dec 11, 2023
89c716f
update to include new settings
abi Dec 11, 2023
9f064c5
after code generation cancellation, leave the app in a good state (re…
abi Dec 11, 2023
b883201
Pre-process history for history display so we can write unit tests fo…
abi Dec 12, 2023
a615f25
improve history UX
abi Dec 13, 2023
896ac66
add a simple eval script to batch run inferences
abi Dec 13, 2023
d23cec9
add a front-end for scoring eval results
abi Dec 13, 2023
9494f4c
fix reset function to reset all state correctly
abi Dec 14, 2023
f1a9859
fix bug with history not being updated if image generation fails
abi Dec 14, 2023
f676151
fix bug with preview not updating immediately
abi Dec 14, 2023
9b728d0
add experimental support for SVG
abi Dec 14, 2023
0c43b5e
Update README.md
abi Dec 20, 2023
9b59b2d
disable pasting which is causing a flurry of requests
abi Dec 21, 2023
e32877f
add some comments
abi Dec 22, 2023
8197eec
Update Troubleshooting.md
Hakeemmidan Jan 7, 2024
2ab95eb
upgrade uvicorn dependency and add a backend start python script
abi Jan 8, 2024
fa7ffdf
add a vue tailwind generation option
abi Jan 8, 2024
5912957
Update README.md
abi Jan 8, 2024
0080a5e
better organization of prompts directory
abi Jan 8, 2024
adda685
update gitignore
abi Jan 8, 2024
15dc74a
improve type checking for stack on backend
abi Jan 8, 2024
1aeb8c4
Type the backend properly to avoid code duplication and ensure type e…
abi Jan 8, 2024
7073879
include type checker
abi Jan 9, 2024
aff0ad0
Update README.md
abi Jan 9, 2024
b8bce72
organize evals code into the evals dir
abi Jan 9, 2024
a8b562e
simplify Stack dropdown generation significantly
abi Jan 9, 2024
3723c81
move stack info to a separate file
abi Jan 9, 2024
7bc368d
update remaining variable names for GeneratedCodeConfig
abi Jan 9, 2024
8a431c0
add an imported code prompt
abi Jan 9, 2024
955d1a6
fix missing key
abi Jan 9, 2024
6d942f3
refactors
abi Jan 9, 2024
34c1f9a
update openAI key missing - error dialog message
abi Jan 11, 2024
c0e084a
update evals
abi Feb 21, 2024
5e2c2b2
add pre-commit to run tests before each commit
abi Feb 23, 2024
27165c0
fix end of file newlines
abi Feb 23, 2024
d58d66d
test committing a failing test
abi Feb 23, 2024
5e3a174
test again with fixed test now
abi Feb 23, 2024
072b286
Update README.md
abi Feb 28, 2024
bd407e5
code clean up
abi Mar 4, 2024
a731e46
Merge branch 'main' of https://github.com/abi/screenshot-to-code
abi Mar 4, 2024
f0ff9b2
fix vs code settings for python import path
abi Mar 4, 2024
1bc26b6
Update README.md
abi Mar 5, 2024
7b62147
support Claude 3 Sonnet
abi Mar 5, 2024
7a266ad
Merge branch 'main' of https://github.com/abi/screenshot-to-code
abi Mar 5, 2024
ae92121
Merge pull request #210 from Hakeemmidan/patch-1
abi Mar 5, 2024
788c93f
Update README.md
abi Mar 5, 2024
0b1bdd4
Delete sweep.yaml
abi Mar 5, 2024
4b908d8
Merge branch 'main' of https://github.com/abi/screenshot-to-code
abi Mar 5, 2024
9e59050
Update README.md
abi Mar 5, 2024
a7e51f6
update error message from anthropic
abi Mar 5, 2024
3a23d9e
add pyright as part of pre-commit (but disable it for now due to fail…
abi Mar 5, 2024
d281006
Merge branch 'main' of https://github.com/abi/screenshot-to-code
abi Mar 5, 2024
c69edeb
send correct media type to Claude
abi Mar 5, 2024
4ed4ec1
Update README.md
abi Mar 5, 2024
4f4d2e3
add evaluation description
abi Mar 5, 2024
647bc2b
Merge branch 'main' of https://github.com/abi/screenshot-to-code
abi Mar 5, 2024
123e8ff
Add Claude prompts file (not used yet - we use the same prompts for b…
abi Mar 6, 2024
f2cb1a4
initial version of blogpost
abi Mar 6, 2024
0245f2c
Update evaluating-claude.md
abi Mar 6, 2024
6029a9b
Update evaluating-claude.md
abi Mar 6, 2024
cd7cd84
Update evaluating-claude.md
abi Mar 6, 2024
d8b75c4
Update README.md
abi Mar 6, 2024
c2f230a
initial version of script
abi Mar 7, 2024
4937a92
support video uploads through the interface
abi Mar 7, 2024
e828feb
Merge pull request #257 from abi/video
abi Mar 7, 2024
28d33a4
do multiple passes for video claude
abi Mar 7, 2024
df0f30d
Create video-to-app
abi Mar 8, 2024
6d283ea
Rename video-to-app to video-to-app.md
abi Mar 8, 2024
3c97a40
highlight video feature
abi Mar 8, 2024
a907ef3
Merge branch 'main' of https://github.com/abi/screenshot-to-code
abi Mar 8, 2024
fa58f2c
add note when input mode is video
abi Mar 8, 2024
a0f5af0
improve mock functionality
abi Mar 8, 2024
caa6301
extract html to show a preview for video mode and switch to .srcdoc w…
abi Mar 8, 2024
cacf78a
show preview of videos (only works for .MP4)
abi Mar 8, 2024
f09b4c7
improve preview for videos by showing the streaming response as it co…
abi Mar 8, 2024
b69edb7
add information about Video to app
abi Mar 8, 2024
451f6c3
Update video-to-app.md
abi Mar 8, 2024
214163b
Update README.md
abi Mar 8, 2024
c08cf0a
support screen recording
abi Mar 14, 2024
a58c95c
add more mock data
abi Mar 14, 2024
87cf6f4
Merge branch 'main' of https://github.com/abi/screenshot-to-code
abi Mar 14, 2024
cdbb78e
add browser tab indicator for coding and update favicon images
abi Mar 14, 2024
1a42f6a
add haiku claude constant
abi Mar 15, 2024
4e30b20
stop the screen sharing stream after it's recording is done
abi Mar 15, 2024
81c4fbe
identify exact llm being used during generation
abi Mar 18, 2024
212aa22
fix bug with using enum as string
abi Mar 19, 2024
b57f34d
close anthropic client after it's done streaming
abi Mar 19, 2024
62272e3
update error message for video
abi Mar 19, 2024
7f44228
fix bug where open AI key is required to use it with Anthropic
abi Mar 19, 2024
6069c2a
Update README.md
abi Mar 20, 2024
6a0201a
fix up mock data
abi Mar 22, 2024
87a44cf
show user a preview of the video and allow them to re-record
abi Mar 22, 2024
7024057
show user a preview of the video and allow them to re-record
abi Mar 22, 2024
48d2ae9
Update README.md
abi Mar 22, 2024
04cb502
Update README.md
abi Mar 22, 2024
fc9b2e0
Update README.md
abi Mar 25, 2024
dc52ff4
store intermediate artifacts for video for easier debugging
abi Mar 25, 2024
9465b67
Merge branch 'main' of https://github.com/abi/screenshot-to-code
abi Mar 25, 2024
08c4132
add a link to tips
abi Mar 25, 2024
7b17e4b
Delete blog/video-to-app.md
abi Mar 25, 2024
11cebfa
Update Troubleshooting.md
abi Mar 30, 2024
5b6d1c4
Update README.md
abi Apr 4, 2024
58a9297
update wording to make it more obvious
abi Apr 4, 2024
64cdc74
add a regenerate button to retry an iteration
abi Apr 4, 2024
4ef26a6
Update README.md
abi Apr 5, 2024
29cea32
improve error UX (particular when no OpenAI API key is found)
abi Apr 10, 2024
483d1e2
handle unknown server error by showing an error message to the user
abi Apr 10, 2024
9e1bcae
remove access code/token functionality
abi Apr 10, 2024
f65fab0
Update README.md
abi Apr 10, 2024
6587b62
clean up model strings and add support for GPT-4 Turbo (Apr 2024)
abi Apr 11, 2024
bb642b3
improve evaluation docs and the way the model is passed into the eval…
abi Apr 11, 2024
2c4450d
Fix: step by step API key generation
milseg Apr 12, 2024
1c864b4
Merge pull request #304 from milseg/patch-1
abi Apr 12, 2024
e3a4cfa
add class names for UI testing
abi Apr 12, 2024
911c008
Merge branch 'main' of https://github.com/abi/screenshot-to-code
abi Apr 15, 2024
a96f8d3
Update README.md
abi Apr 15, 2024
d103c02
make turbo the default and move to top of list
abi Apr 15, 2024
ba5c0fe
Merge branch 'main' of https://github.com/abi/screenshot-to-code
abi Apr 15, 2024
f9c4dd9
add react + gpt-4 turbo warning
abi Apr 18, 2024
a5fe096
support best of n evals
abi Apr 24, 2024
8e6a9c4
support GPT-4o
abi May 13, 2024
43214bb
add another unit test for new model
abi May 13, 2024
ffb67d4
Update README.md
abi May 13, 2024
3c82b65
Update README.md
abi May 13, 2024
0cbc5db
Update README.md
abi May 13, 2024
22101ca
Update README.md
abi May 13, 2024
9e36145
add GPT4o message
abi May 14, 2024
01022ab
Update issue templates
abi May 16, 2024
1f61d02
Update issue templates
abi May 16, 2024
ac8198e
Add field for Anthropic API key in settings
abi May 17, 2024
1f9c5b2
set initial value
abi May 17, 2024
72d412f
set up a basic puppeteer test
abi May 17, 2024
7396160
clean up the code
abi May 17, 2024
610400b
also iterate through stacks
abi May 17, 2024
992344a
add testing for edits
abi May 17, 2024
dbd1ea0
remove console.log
abi May 20, 2024
9a23426
clean up test code
abi May 20, 2024
a3104fa
make env vars work
abi May 20, 2024
ce82fc8
read fixtures path from env var
abi May 20, 2024
5c598da
add example for jest env
abi May 20, 2024
726ecaf
fix up update tests
abi May 20, 2024
df38041
attempt to test import from code
abi May 20, 2024
f01403d
Merge branch 'main' into qa-testing
abi May 20, 2024
55a0a6c
minor fixes
abi May 20, 2024
9882447
add comments
abi May 21, 2024
bf38200
Merge pull request #337 from abi/qa-testing
abi May 21, 2024
bef9aa8
Update README.md
abi May 23, 2024
23e6317
Create FUNDING.yml
abi May 23, 2024
9395396
Update README.md
abi May 29, 2024
9d1fbc9
add zustand and create a dummy app store that isn't used yet
abi May 30, 2024
8e579e4
clean up settings dialog look
abi May 31, 2024
c64968b
read anthropic api key from front-end
abi May 31, 2024
0959441
Merge branch 'main' into add-anthropic-key
abi May 31, 2024
f6f8b2f
fix bug
abi May 31, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: [abi]
21 changes: 21 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Screenshots of backend AND frontend terminal logs**
If applicable, add screenshots to help explain your problem.
10 changes: 10 additions & 0 deletions .github/ISSUE_TEMPLATE/custom.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
name: Custom issue template
about: Describe this issue template's purpose here.
title: ''
labels: ''
assignees: ''

---


20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ backend/backend/*
# Env vars
frontend/.env.local
.env

# Mac files
.DS_Store
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"python.analysis.typeCheckingMode": "strict",
"python.analysis.extraPaths": ["./backend"],
"python.autoComplete.extraPaths": ["./backend"]
}
19 changes: 19 additions & 0 deletions Evaluation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## Evaluating models and prompts

Evaluation dataset consists of 16 screenshots. A Python script for running screenshot-to-code on the dataset and a UI for rating outputs is included. With this set up, we can compare and evaluate various models and prompts.

### Running evals

- Input screenshots should be located at `backend/evals_data/inputs` and the outputs will be `backend/evals_data/outputs`. If you want to modify this, modify `EVALS_DIR` in `backend/evals/config.py`. You can download the input screenshot dataset here: TODO.
- Set a stack and model (`STACK` var, `MODEL` var) in `backend/run_evals.py`
- Run `OPENAI_API_KEY=sk-... python run_evals.py` - this runs the screenshot-to-code on the input dataset in parallel but it will still take a few minutes to complete.
- Once the script is done, you can find the outputs in `backend/evals_data/outputs`.

### Rating evals

In order to view and rate the outputs, visit your front-end at `/evals`.

- Rate each output on a scale of 1-4
- You can also print the page as PDF to share your results with others.

Generally, I run three tests for each model/prompt + stack combo and take the average score out of those tests to evaluate.
54 changes: 39 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,48 @@
# screenshot-to-code

This simple app converts a screenshot to code (HTML/Tailwind CSS, or React or Vue or Bootstrap). It uses GPT-4 Vision to generate the code and DALL-E 3 to generate similar-looking images. You can now also enter a URL to clone a live website!
A simple tool to convert screenshots, mockups and Figma designs into clean, functional code using AI. **Now supporting GPT-4O!**

https://github.com/abi/screenshot-to-code/assets/23818/6cebadae-2fe3-4986-ac6a-8fb9db030045

See the [Examples](#examples) section below for more demos.
Supported stacks:

## 🚀 Try It Out!
- HTML + Tailwind
- React + Tailwind
- Vue + Tailwind
- Bootstrap
- Ionic + Tailwind
- SVG

🆕 [Try it here](https://screenshottocode.com) (bring your own OpenAI key - **your key must have access to GPT-4 Vision. See [FAQ](#%EF%B8%8F-faqs) section below for details**). Or see [Getting Started](#-getting-started) below for local install instructions.
Supported AI models:

## 🌟 Recent Updates
- GPT-4O - Best model!
- GPT-4 Turbo (Apr 2024)
- GPT-4 Vision (Nov 2023)
- Claude 3 Sonnet
- DALL-E 3 for image generation

- Nov 28 - 🔥 🔥 🔥 Get output code in React or Bootstrap or TailwindCSS
- Nov 23 - Send in a screenshot of the current replicated version (sometimes improves quality of subsequent generations)
- Nov 21 - Edit code in the code editor and preview changes live thanks to [@clean99](https://github.com/clean99)
- Nov 20 - Paste in a URL to screenshot and clone (requires [ScreenshotOne free API key](https://screenshotone.com?via=screenshot-to-code))
- Nov 19 - Support for dark/light code editor theme - thanks [@kachbit](https://github.com/kachbit)
- Nov 16 - Added a setting to disable DALL-E image generation if you don't need that
- Nov 16 - View code directly within the app
- Nov 15 - You can now instruct the AI to update the code as you wish. It is helpful if the AI messed up some styles or missed a section.
See the [Examples](#-examples) section below for more demos.

We also just added experimental support for taking a video/screen recording of a website in action and turning that into a functional prototype.

![google in app quick 3](https://github.com/abi/screenshot-to-code/assets/23818/8758ffa4-9483-4b9b-bb66-abd6d1594c33)

[Learn more about video here](https://github.com/abi/screenshot-to-code/wiki/Screen-Recording-to-Code).

[Follow me on Twitter for updates](https://twitter.com/_abi_).

## Sponsors

<a href="https://konghq.com/products/kong-konnect/register?utm_medium=referral&utm_source=github&utm_campaign=platform&utm_content=screenshot-to-code" target="_blank" title="Kong - powering the API world"><img src="https://picoapps.xyz/s2c-sponsors/Kong-GitHub-240x100.png"></a>


## 🚀 Try It Out without no install

[Try it live on the hosted version (paid)](https://screenshottocode.com).

## 🛠 Getting Started

The app has a React/Vite frontend and a FastAPI backend. You will need an OpenAI API key with access to the GPT-4 Vision API.
The app has a React/Vite frontend and a FastAPI backend. You will need an OpenAI API key with access to the GPT-4 Vision API or an Anthropic key if you want to use Claude Sonnet, or for experimental video support.

Run the backend (I use Poetry for package management - `pip install poetry` if you don't have it):

Expand All @@ -35,6 +54,8 @@ poetry shell
poetry run uvicorn main:app --reload --port 7001
```

If you want to use Anthropic, add the `ANTHROPIC_API_KEY` to `backend/.env` with your API key from Anthropic.

Run the frontend:

```bash
Expand Down Expand Up @@ -68,6 +89,9 @@ The app will be up and running at http://localhost:5173. Note that you can't dev

- **I'm running into an error when setting up the backend. How can I fix it?** [Try this](https://github.com/abi/screenshot-to-code/issues/3#issuecomment-1814777959). If that still doesn't work, open an issue.
- **How do I get an OpenAI API key?** See https://github.com/abi/screenshot-to-code/blob/main/Troubleshooting.md
- **How can I configure an OpenAI proxy?** - If you're not able to access the OpenAI API directly (due to e.g. country restrictions), you can try a VPN or you can configure the OpenAI base URL to use a proxy: Set OPENAI_BASE_URL in the `backend/.env` or directly in the UI in the settings dialog. Make sure the URL has "v1" in the path so it should look like this: `https://xxx.xxxxx.xxx/v1`
- **How can I update the backend host that my front-end connects to?** - Configure VITE_HTTP_BACKEND_URL and VITE_WS_BACKEND_URL in front/.env.local For example, set VITE_HTTP_BACKEND_URL=http://124.10.20.1:7001
- **Seeing UTF-8 errors when running the backend?** - On windows, open the .env file with notepad++, then go to Encoding and select UTF-8.
- **How can I provide feedback?** For feedback, feature requests and bug reports, open an issue or ping me on [Twitter](https://twitter.com/_abi_).

## 📚 Examples
Expand All @@ -88,6 +112,6 @@ https://github.com/abi/screenshot-to-code/assets/23818/3fec0f77-44e8-4fb3-a769-a

## 🌍 Hosted Version

🆕 [Try it here](https://screenshottocode.com) (bring your own OpenAI key - **your key must have access to GPT-4 Vision. See [FAQ](#%EF%B8%8F-faqs) section for details**). Or see [Getting Started](#-getting-started) for local install instructions.
🆕 [Try it here (paid)](https://screenshottocode.com). Or see [Getting Started](#-getting-started) for local install instructions to use with your own API keys.

[!["Buy Me A Coffee"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/abiraja)
18 changes: 12 additions & 6 deletions Troubleshooting.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
### Getting an OpenAI API key
### Getting an OpenAI API key with GPT4-Vision model access

You don't need a ChatGPT Pro account. Screenshot to code uses API keys from your OpenAI developer account. In order to get access to the GPT4 Vision model, log into your OpenAI account and then, follow these instructions:

1. Open [OpenAI Dashboard](https://platform.openai.com/)
1. Go to Settings > Billing
1. Click at the Add payment details
<img width="1030" alt="285636868-c80deb92-ab47-45cd-988f-deee67fbd44d" src="https://github.com/abi/screenshot-to-code/assets/23818/4e0f4b77-9578-4f9a-803c-c12b1502f3d7">
4. You have to buy some credits. The minimum is $5.
<img width="900" alt="285636868-c80deb92-ab47-45cd-988f-deee67fbd44d" src="https://github.com/abi/screenshot-to-code/assets/23818/4e0f4b77-9578-4f9a-803c-c12b1502f3d7">

4. You have to buy some credits. The minimum is $5.
5. Go to Settings > Limits and check at the bottom of the page, your current tier has to be "Tier 1" to have GPT4 access
<img width="785" alt="285636973-da38bd4d-8a78-4904-8027-ca67d729b933" src="https://github.com/abi/screenshot-to-code/assets/23818/8d07cd84-0cf9-4f88-bc00-80eba492eadf">
<img width="900" alt="285636973-da38bd4d-8a78-4904-8027-ca67d729b933" src="https://github.com/abi/screenshot-to-code/assets/23818/8d07cd84-0cf9-4f88-bc00-80eba492eadf">

6. Navigate to OpenAI [api keys](https://platform.openai.com/api-keys) page and create and copy a new secret key.
7. Go to Screenshot to code and paste it in the Settings dialog under OpenAI key (gear icon). Your key is only stored in your browser. Never stored on our servers.

## Still not working?

Some users have also reported that it can take upto 30 minutes after your credit purchase for the GPT4 vision model to be activated.
- Some users have also reported that it can take upto 30 minutes after your credit purchase for the GPT4 vision model to be activated.
- You need to add credits to your account AND set it to renew when credits run out in order to be upgraded to Tier 1. Make sure your "Settings > Limits" page shows that you are at Tier 1.

If you've followed these steps, and it still doesn't work, feel free to open a Github issue.
If you've followed these steps, and it still doesn't work, feel free to open a Github issue. We only provide support for the open source version since we don't have debugging logs on the hosted version. If you're looking to use the hosted version, we recommend getting a paid subscription on screenshottocode.com
8 changes: 8 additions & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,11 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/


# Temporary eval output
evals_data


# Temporary video evals (Remove before merge)
video_evals
25 changes: 25 additions & 0 deletions backend/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- repo: local
hooks:
- id: poetry-pytest
name: Run pytest with Poetry
entry: poetry run --directory backend pytest
language: system
pass_filenames: false
always_run: true
files: ^backend/
# - id: poetry-pyright
# name: Run pyright with Poetry
# entry: poetry run --directory backend pyright
# language: system
# pass_filenames: false
# always_run: true
# files: ^backend/
8 changes: 6 additions & 2 deletions backend/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Run tests
# Run the type checker

pytest test_prompts.py
poetry run pyright

# Run tests

poetry run pytest
25 changes: 0 additions & 25 deletions backend/access_token.py

This file was deleted.

16 changes: 16 additions & 0 deletions backend/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Useful for debugging purposes when you don't want to waste GPT4-Vision credits
# Setting to True will stream a mock response instead of calling the OpenAI API
# TODO: Should only be set to true when value is 'True', not any abitrary truthy value
import os

ANTHROPIC_API_KEY = os.environ.get("ANTHROPIC_API_KEY", None)

# Debugging-related

SHOULD_MOCK_AI_RESPONSE = bool(os.environ.get("MOCK", False))
IS_DEBUG_ENABLED = bool(os.environ.get("IS_DEBUG_ENABLED", False))
DEBUG_DIR = os.environ.get("DEBUG_DIR", "")

# Set to True when running in production (on the hosted version)
# Used as a feature flag to enable or disable certain features
IS_PROD = os.environ.get("IS_PROD", False)
7 changes: 7 additions & 0 deletions backend/custom_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from typing import Literal


InputMode = Literal[
"image",
"video",
]
30 changes: 30 additions & 0 deletions backend/debug/DebugFileWriter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import os
import logging
import uuid

from config import DEBUG_DIR, IS_DEBUG_ENABLED


class DebugFileWriter:
def __init__(self):
if not IS_DEBUG_ENABLED:
return

try:
self.debug_artifacts_path = os.path.expanduser(
f"{DEBUG_DIR}/{str(uuid.uuid4())}"
)
os.makedirs(self.debug_artifacts_path, exist_ok=True)
print(f"Debugging artifacts will be stored in: {self.debug_artifacts_path}")
except:
logging.error("Failed to create debug directory")

def write_to_file(self, filename: str, content: str) -> None:
try:
with open(os.path.join(self.debug_artifacts_path, filename), "w") as file:
file.write(content)
except Exception as e:
logging.error(f"Failed to write to file: {e}")

def extract_html_content(self, text: str) -> str:
return str(text.split("<html>")[-1].rsplit("</html>", 1)[0] + "</html>")
Empty file added backend/debug/__init__.py
Empty file.
Empty file added backend/evals/__init__.py
Empty file.
1 change: 1 addition & 0 deletions backend/evals/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
EVALS_DIR = "./evals_data"
39 changes: 39 additions & 0 deletions backend/evals/core.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import os
from config import ANTHROPIC_API_KEY

from llm import Llm, stream_claude_response, stream_openai_response
from prompts import assemble_prompt
from prompts.types import Stack


async def generate_code_core(image_url: str, stack: Stack, model: Llm) -> str:
prompt_messages = assemble_prompt(image_url, stack)
openai_api_key = os.environ.get("OPENAI_API_KEY")
anthropic_api_key = ANTHROPIC_API_KEY
openai_base_url = None

async def process_chunk(content: str):
pass

if model == Llm.CLAUDE_3_SONNET:
if not anthropic_api_key:
raise Exception("Anthropic API key not found")

completion = await stream_claude_response(
prompt_messages,
api_key=anthropic_api_key,
callback=lambda x: process_chunk(x),
)
else:
if not openai_api_key:
raise Exception("OpenAI API key not found")

completion = await stream_openai_response(
prompt_messages,
api_key=openai_api_key,
base_url=openai_base_url,
callback=lambda x: process_chunk(x),
model=model,
)

return completion
7 changes: 7 additions & 0 deletions backend/evals/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import base64


async def image_to_data_url(filepath: str):
with open(filepath, "rb") as image_file:
encoded_string = base64.b64encode(image_file.read()).decode()
return f"data:image/png;base64,{encoded_string}"
Loading