Skip to content

Commit f9a66d4

Browse files
committed
Merge branch 'main' into lendemor/deploy_pipeline
2 parents f05add4 + 4575440 commit f9a66d4

File tree

11 files changed

+119
-1
lines changed

11 files changed

+119
-1
lines changed

.github/workflows/check_export.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ jobs:
3535
runs-on: ubuntu-latest
3636
steps:
3737
- uses: actions/checkout@v4
38+
with:
39+
submodules: recursive
3840
- uses: actions/setup-python@v5
3941
with:
4042
python-version: 3.9

.github/workflows/create-artifacts.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ jobs:
88
outputs:
99
files: ${{ steps.list_zip_files.outputs.files }}
1010
steps:
11-
- name: Checkout code
11+
- name: Checkout code with submodules
1212
uses: actions/checkout@v3
13+
with:
14+
submodules: recursive
1315
- name: Create zip files for each subfolder
1416
run: |
1517
for dir in $(find . -mindepth 1 -maxdepth 1 -type d); do

.gitmodules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[submodule "reflex-chat"]
2+
path = reflex-chat
3+
url = https://github.com/reflex-dev/reflex-chat.git
4+
[submodule "reflex-llamaindex-template"]
5+
path = reflex-llamaindex-template
6+
url = https://github.com/reflex-dev/reflex-llamaindex-template.git

dalle/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*.db
2+
*.py[cod]
3+
.web
4+
__pycache__/
5+
reflex.db

dalle/assets/favicon.ico

4.19 KB
Binary file not shown.

dalle/dalle/__init__.py

Whitespace-only changes.

dalle/dalle/dalle.py

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
"""Welcome to Reflex! This file outlines the steps to create a basic app."""
2+
3+
import reflex as rx
4+
5+
import os
6+
7+
import openai
8+
9+
_client = None
10+
11+
12+
def get_openai_client():
13+
global _client
14+
if _client is None:
15+
_client = openai.OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
16+
17+
return _client
18+
19+
20+
class State(rx.State):
21+
"""The app state."""
22+
23+
image_url = ""
24+
image_processing = False
25+
image_made = False
26+
27+
def get_dalle_result(self, form_data: dict[str, str]):
28+
prompt_text: str = form_data["prompt_text"]
29+
self.image_made = False
30+
self.image_processing = True
31+
# Yield here so the image_processing take effects and the circular progress is shown.
32+
yield
33+
try:
34+
response = get_openai_client().images.generate(
35+
prompt=prompt_text, n=1, size="1024x1024"
36+
)
37+
self.image_url = response.data[0].url
38+
self.image_processing = False
39+
self.image_made = True
40+
yield
41+
except Exception as ex:
42+
self.image_processing = False
43+
yield rx.window_alert(f"Error with OpenAI Execution. {ex}")
44+
45+
46+
def index():
47+
return rx.center(
48+
rx.vstack(
49+
rx.heading("DALL-E", font_size="1.5em"),
50+
rx.form(
51+
rx.vstack(
52+
rx.input(
53+
id="prompt_text",
54+
placeholder="Enter a prompt..",
55+
size="3",
56+
),
57+
rx.button(
58+
"Generate Image",
59+
type="submit",
60+
size="3",
61+
),
62+
align="stretch",
63+
spacing="2",
64+
),
65+
width="100%",
66+
on_submit=State.get_dalle_result,
67+
),
68+
rx.divider(),
69+
rx.cond(
70+
State.image_processing,
71+
rx.spinner(),
72+
rx.cond(
73+
State.image_made,
74+
rx.image(
75+
src=State.image_url,
76+
),
77+
),
78+
),
79+
width="25em",
80+
bg="white",
81+
padding="2em",
82+
align="center",
83+
),
84+
width="100%",
85+
height="100vh",
86+
background="radial-gradient(circle at 22% 11%,rgba(62, 180, 137,.20),hsla(0,0%,100%,0) 19%),radial-gradient(circle at 82% 25%,rgba(33,150,243,.18),hsla(0,0%,100%,0) 35%),radial-gradient(circle at 25% 61%,rgba(250, 128, 114, .28),hsla(0,0%,100%,0) 55%)",
87+
)
88+
89+
90+
# Add state and page to the app.
91+
app = rx.App(
92+
theme=rx.theme(
93+
appearance="light", has_background=True, radius="medium", accent_color="mint"
94+
),
95+
)
96+
app.add_page(index, title="Reflex:DALL-E")

dalle/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
reflex>=0.4.0
2+
openai>=1

dalle/rxconfig.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import reflex as rx
2+
3+
config = rx.Config(app_name="dalle")

reflex-chat

Submodule reflex-chat added at fa8f03d

0 commit comments

Comments
 (0)