Skip to content

Commit b87d26e

Browse files
authored
use templates endpoint (#1357)
* use templates endpoint * change rx_backend url
1 parent a670968 commit b87d26e

File tree

3 files changed

+44
-23
lines changed

3 files changed

+44
-23
lines changed

pcweb/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
SCREENSHOT_BUCKET = "https://pub-c14a5dcf674640a6b73fded32bad72ca.r2.dev/"
6565

6666
# Reflex Cloud Backend
67-
RX_CLOUD_BACKEND = os.getenv("RX_CLOUD_BACKEND", "https://cloud-f188e2cd-51fb-4b29-b546-2ce4b9efc5d5.fly.dev/")
67+
RX_CLOUD_BACKEND = os.getenv("RX_CLOUD_BACKEND", "https://cloud-backend.reflex.dev/")
6868

6969

7070
# Stats

pcweb/pages/landing/views/ai_section.py

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,46 @@
22
import httpx
33
from pcweb.components.icons.hugeicons import hi
44
from pcweb.constants import SCREENSHOT_BUCKET, REFLEX_BUILD_URL, RX_CLOUD_BACKEND
5+
import asyncio
6+
import contextlib
57

8+
TEMPLATES_LIST = [
9+
"bbfcc0b8-8f09-4211-884e-7ad2f1a36906",
10+
"e6293a74-4a47-44a3-bc1e-8966863feb46",
11+
"a7f5bf05-a34a-4b40-a39f-4f6c71ded78f",
12+
"dd3a7d49-e174-41d3-8856-cad921a98749",
13+
"576aab1d-e733-42fa-a13e-515fd72ba012",
14+
"28194790-f5cc-4625-bd30-cf2693890e08",
15+
"7e5346b7-025c-4ff3-9b32-c1b9d7afcaec",
16+
"2f969644-3140-4dbb-b639-5d0a940603c2",
17+
"47f86c01-59ec-4088-b47a-64ceddf58a6e",
18+
"98afee02-538f-4334-ab10-f05c1c3d564b",
19+
]
620

7-
class AIBuilderGallery(rx.State):
8-
items: list[str] = [
9-
"bbfcc0b8-8f09-4211-884e-7ad2f1a36906",
10-
"e6293a74-4a47-44a3-bc1e-8966863feb46",
11-
"a7f5bf05-a34a-4b40-a39f-4f6c71ded78f",
12-
"dd3a7d49-e174-41d3-8856-cad921a98749",
13-
"576aab1d-e733-42fa-a13e-515fd72ba012",
14-
"28194790-f5cc-4625-bd30-cf2693890e08",
15-
"7e5346b7-025c-4ff3-9b32-c1b9d7afcaec",
16-
"2f969644-3140-4dbb-b639-5d0a940603c2",
17-
"47f86c01-59ec-4088-b47a-64ceddf58a6e",
18-
"98afee02-538f-4334-ab10-f05c1c3d564b",
19-
]
2021

21-
# @rx.event
22-
# async def fetch_items(self):
23-
# async with httpx.AsyncClient() as client:
24-
# response = await client.get(f"{RX_CLOUD_BACKEND}v1/flexgen/templates")
25-
# # self.items = response.json()
22+
async def retreive_templates():
23+
"""Fetch and update the TEMPLATES_LIST."""
24+
try:
25+
while True:
26+
with contextlib.suppress(Exception):
27+
async with httpx.AsyncClient() as client:
28+
global TEMPLATES_LIST
29+
response = await client.get(
30+
f"{RX_CLOUD_BACKEND}v1/flexgen/templates",
31+
)
32+
response_data = response.json()
33+
if isinstance(response_data, list):
34+
TEMPLATES_LIST = response_data
35+
36+
await asyncio.sleep(60 * 10)
37+
except asyncio.CancelledError:
38+
pass
39+
40+
41+
class AIBuilderGallery(rx.State):
42+
@rx.var(interval=60 * 10)
43+
def items(self) -> list[str]:
44+
return TEMPLATES_LIST
2645

2746

2847
def header() -> rx.Component:
@@ -76,6 +95,5 @@ def ai_section() -> rx.Component:
7695
return rx.el.section(
7796
header(),
7897
gallery(),
79-
# on_mount=AIBuilderGallery.fetch_items,
8098
class_name="flex flex-col mx-auto w-full max-w-[84.19rem]",
8199
)

pcweb/pcweb.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from pcweb.whitelist import _check_whitelisted_path
1111
from pcweb.telemetry import get_pixel_website_trackers
1212
from pcweb.meta.meta import favicons_links
13+
from pcweb.pages.landing.views.ai_section import retreive_templates
1314

1415
# This number discovered by trial and error on Windows 11 w/ Node 18, any
1516
# higher and the prod build fails with EMFILE error.
@@ -47,6 +48,8 @@
4748
],
4849
)
4950

51+
app.register_lifespan_task(retreive_templates)
52+
5053
# XXX: The app is TOO BIG to build on Windows, so explicitly disallow it except for testing
5154
if sys.platform == "win32":
5255
if not os.environ.get("REFLEX_WEB_WINDOWS_OVERRIDE"):
@@ -64,9 +67,9 @@
6467
"component": route.component,
6568
"route": route.path,
6669
"title": route.title,
67-
"image": "/previews/index_preview.png"
68-
if route.image is None
69-
else route.image,
70+
"image": (
71+
"/previews/index_preview.png" if route.image is None else route.image
72+
),
7073
"meta": [
7174
{"name": "theme-color", "content": route.background_color},
7275
],

0 commit comments

Comments
 (0)