Skip to content

Drop in a screenshot and convert it to clean code (HTML/Tailwind/React/Vue)

Python

return early if there are no images to replace

Abi Raja68dd33cf064c
diff --git a/backend/image_generation.py b/backend/image_generation.py
index 336cc6e6..e1230a81 100644
--- a/backend/image_generation.py
+++ b/backend/image_generation.py
@@ -82,6 +82,10 @@ async def generate_images(code, image_cache):
# Remove duplicates
prompts = list(set(alts))
+ # Return early if there are no images to replace
+ if len(prompts) == 0:
+ return code
+
# Generate images
results = await process_tasks(prompts)
diff --git a/backend/main.py b/backend/main.py
index 5abd3330..3980ffe8 100644
--- a/backend/main.py
+++ b/backend/main.py
@@ -11,7 +11,7 @@ from datetime import datetime
from fastapi import FastAPI, WebSocket
from llm import stream_openai_response
-from mock import MOCK_HTML, mock_completion
+from mock import mock_completion
from image_generation import create_alt_url_mapping, generate_images
from prompts import assemble_prompt
@@ -41,6 +41,7 @@ async def stream_code_test(websocket: WebSocket):
params = await websocket.receive_json()
+ print("generating code...")
await websocket.send_json({"type": "status", "value": "Generating code..."})
async def process_chunk(content):
diff --git a/backend/mock.py b/backend/mock.py
index ec263395..90dc7d36 100644
--- a/backend/mock.py
+++ b/backend/mock.py
@@ -2,7 +2,7 @@ import asyncio
async def mock_completion(process_chunk):
- code_to_return = MOCK_HTML_2
+ code_to_return = NO_IMAGES_NYTIMES_MOCK_CODE
for i in range(0, len(code_to_return), 10):
await process_chunk(code_to_return[i : i + 10])
@@ -11,7 +11,7 @@ async def mock_completion(process_chunk):
return code_to_return
-MOCK_HTML = """<html lang="en">
+APPLE_MOCK_CODE = """<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
@@ -68,7 +68,7 @@ MOCK_HTML = """<html lang="en">
</body>
</html>"""
-MOCK_HTML_2 = """
+NYTIMES_MOCK_CODE = """
<html lang="en">
<head>
<meta charset="UTF-8">
@@ -138,3 +138,70 @@ MOCK_HTML_2 = """
</body>
</html>
"""
+
+NO_IMAGES_NYTIMES_MOCK_CODE = """
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <title>The New York Times - News</title>
+ <script src="https://cdn.tailwindcss.com"></script>
+ <link href="https://fonts.googleapis.com/css2?family=Libre+Franklin:wght@300;400;700&display=swap" rel="stylesheet">
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
+ <style>
+ body {
+ font-family: 'Libre Franklin', sans-serif;
+ }
+ </style>
+</head>
+<body class="bg-gray-100">
+ <div class="container mx-auto px-4">
+ <header class="border-b border-gray-300 py-4">
+ <div class="flex justify-between items-center">
+ <div class="flex items-center space-x-4">
+ <button class="text-gray-700"><i class="fas fa-bars"></i></button>
+ <button class="text-gray-700"><i class="fas fa-search"></i></button>
+ <div class="text-xs uppercase tracking-widest">Tuesday, November 14, 2023<br>Today's Paper</div>
+ </div>
+ <div class="flex items-center space-x-4">
+ <button class="bg-black text-white px-4 py-1 text-xs uppercase tracking-widest">Give the times</button>
+ <div class="text-xs">Account</div>
+ </div>
+ </div>
+ <nav class="flex justify-between items-center py-4">
+ <div class="flex space-x-4">
+ <a href="#" class="text-xs uppercase tracking-widest text-gray-700">U.S.</a>
+ <!-- Add other navigation links as needed -->
+ </div>
+ <div class="flex space-x-4">
+ <a href="#" class="text-xs uppercase tracking-widest text-gray-700">Cooking</a>
+ <!-- Add other navigation links as needed -->
+ </div>
+ </nav>
+ </header>
+ <main>
+ <section class="py-6">
+ <div class="grid grid-cols-3 gap-4">
+ <div class="col-span-2">
+ <article class="mb-4">
+ <h2 class="text-xl font-bold mb-2">Israeli Military Raids Gaza’s Largest Hospital</h2>
+ <p class="text-gray-700 mb-2">Israeli troops have entered the Al-Shifa Hospital complex, where conditions have grown dire and Israel says Hamas fighters are embedded.</p>
+ <a href="#" class="text-blue-600 text-sm">See more updates <i class="fas fa-external-link-alt"></i></a>
+ </article>
+ <!-- Repeat for each news item -->
+ </div>
+ <div class="col-span-1">
+ <article class="mb-4">
+ <h2 class="text-xl font-bold mb-2">From Elvis to Elopements, the Evolution of the Las Vegas Wedding</h2>
+ <p class="text-gray-700 mb-2">The glittering city that attracts thousands of couples seeking unconventional nuptials has grown beyond the drive-through wedding.</p>
+ <a href="#" class="text-blue-600 text-sm">8 MIN READ</a>
+ </article>
+ <!-- Repeat for each news item -->
+ </div>
+ </div>
+ </section>
+ </main>
+ </div>
+</body>
+</html>
+"""