|
2 | 2 | import httpx |
3 | 3 | from pcweb.components.icons.hugeicons import hi |
4 | 4 | from pcweb.constants import SCREENSHOT_BUCKET, REFLEX_BUILD_URL, RX_CLOUD_BACKEND |
| 5 | +import asyncio |
| 6 | +import contextlib |
5 | 7 |
|
| 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 | +] |
6 | 20 |
|
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 | | - ] |
20 | 21 |
|
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 |
26 | 45 |
|
27 | 46 |
|
28 | 47 | def header() -> rx.Component: |
@@ -76,6 +95,5 @@ def ai_section() -> rx.Component: |
76 | 95 | return rx.el.section( |
77 | 96 | header(), |
78 | 97 | gallery(), |
79 | | - # on_mount=AIBuilderGallery.fetch_items, |
80 | 98 | class_name="flex flex-col mx-auto w-full max-w-[84.19rem]", |
81 | 99 | ) |
0 commit comments