diff --git a/backend/image_generation.py b/backend/image_generation.py index 336cc6e..e1230a8 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 5abd333..3980ffe 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 ec26339..90dc7d3 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 = """ +APPLE_MOCK_CODE = """ @@ -68,7 +68,7 @@ MOCK_HTML = """ """ -MOCK_HTML_2 = """ +NYTIMES_MOCK_CODE = """ @@ -138,3 +138,70 @@ MOCK_HTML_2 = """ """ + +NO_IMAGES_NYTIMES_MOCK_CODE = """ + + + + + The New York Times - News + + + + + + +
+
+
+
+ + +
Tuesday, November 14, 2023
Today's Paper
+
+
+ +
Account
+
+
+ +
+
+
+
+
+
+

Israeli Military Raids Gaza’s Largest Hospital

+

Israeli troops have entered the Al-Shifa Hospital complex, where conditions have grown dire and Israel says Hamas fighters are embedded.

+ See more updates +
+ +
+
+
+

From Elvis to Elopements, the Evolution of the Las Vegas Wedding

+

The glittering city that attracts thousands of couples seeking unconventional nuptials has grown beyond the drive-through wedding.

+ 8 MIN READ +
+ +
+
+
+
+
+ + +"""