From 54156619aa67059b910f56cc179608884362bc6a Mon Sep 17 00:00:00 2001 From: Carlos Date: Fri, 18 Oct 2024 21:07:15 +0200 Subject: [PATCH] add flux fast app --- flux-fast/.gitignore | 5 +++ flux-fast/assets/favicon.ico | Bin 0 -> 4286 bytes flux-fast/flux_fast/__init__.py | 0 flux-fast/flux_fast/flux_fast.py | 70 +++++++++++++++++++++++++++++++ flux-fast/requirements.txt | 1 + flux-fast/rxconfig.py | 5 +++ 6 files changed, 81 insertions(+) create mode 100644 flux-fast/.gitignore create mode 100644 flux-fast/assets/favicon.ico create mode 100644 flux-fast/flux_fast/__init__.py create mode 100644 flux-fast/flux_fast/flux_fast.py create mode 100644 flux-fast/requirements.txt create mode 100644 flux-fast/rxconfig.py diff --git a/flux-fast/.gitignore b/flux-fast/.gitignore new file mode 100644 index 00000000..139ed98a --- /dev/null +++ b/flux-fast/.gitignore @@ -0,0 +1,5 @@ +*.db +*.py[cod] +.web +__pycache__/ +assets/external/ diff --git a/flux-fast/assets/favicon.ico b/flux-fast/assets/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..166ae995eaa63fc96771410a758282dc30e925cf GIT binary patch literal 4286 zcmeHL>rYc>81ELdEe;}zmYd}cUgmJRfwjUwD1`#s5KZP>mMqza#Viv|_7|8f+0+bX zHuqusuw-7Ca`DTu#4U4^o2bjO#K>4%N?Wdi*wZ3Vx%~Ef4}D1`U_EMRg3u z#2#M|V>}}q-@IaO@{9R}d*u7f&~5HfxSkmHVcazU#i30H zAGxQ5Spe!j9`KuGqR@aExK`-}sH1jvqoIp3C7Vm)9Tu=UPE;j^esN~a6^a$ZILngo;^ zGLXl(ZFyY&U!li`6}y-hUQ99v?s`U4O!kgog74FPw-9g+V)qs!jFGEQyvBf><U|E2vRmx|+(VI~S=lT?@~C5pvZOd`x{Q_+3tG6H=gtdWcf z)+7-Zp=UqH^J4sk^>_G-Ufn-2Hz z2mN12|C{5}U`^eCQuFz=F%wp@}SzA1MHEaM^CtJs<{}Tzu$bx2orTKiedgmtVGM{ zdd#vX`&cuiec|My_KW;y{Ryz2kFu9}=~us6hvx1ZqQCk(d+>HP>ks>mmHCjjDh{pe zKQkKpk0SeDX#XMqf$}QV{z=xrN!mQczJAvud@;zFqaU1ocq==Py)qsa=8UKrt!J7r z{RsTo^rgtZo%$rak)DN*D)!(Y^$@yL6Nd=#eu&?unzhH8yq>v{gkt8xcG3S%H)-y_ zqQ1|v|JT$0R~Y}omg2Y+nDvR+K|kzR5i^fmKF>j~N;A35Vr`JWh4yRqKl#P|qlx?` z@|CmBiP}ysYO%m2{eBG6&ix5 zr#u((F2{vb=W4jNmTQh3M^F2o80T49?w>*rv0mt)-o1y!{hRk`E#UVPdna6jnz`rw dKpn)r^--YJZpr;bYU`N~>#v3X5BRU&{{=gv-{1fM literal 0 HcmV?d00001 diff --git a/flux-fast/flux_fast/__init__.py b/flux-fast/flux_fast/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/flux-fast/flux_fast/flux_fast.py b/flux-fast/flux_fast/flux_fast.py new file mode 100644 index 00000000..a96c53f1 --- /dev/null +++ b/flux-fast/flux_fast/flux_fast.py @@ -0,0 +1,70 @@ +import reflex as rx + + +class FluxState(rx.State): + """State for the flux.""" + + images_list: list[str] = [] + + def set_prompt(self, prompt: str): + """Set the prompt.""" + # If more than 30 images, clear the list + if len(self.images_list) > 30: + self.images_list = [] + self.images_list.append( + f"https://fast-flux-demo.replicate.workers.dev/api/generate-image?text={prompt}" + ) + + +def input_bar() -> rx.Component: + return rx.el.input( + placeholder="Type to generate images...", + on_change=FluxState.set_prompt, + class_name="border-[--slate-5] bg-[--slate-1] focus:shadow-[0px_0px_0px_2px_var(--accent-4)] px-2.5 border rounded-[0.625rem] w-full h-[3rem] text-[--slate-12] text-md placeholder:text-[--slate-9] outline-none focus:outline-none max-w-[40rem]", + ) + + +def image_card(prompt: str) -> rx.Component: + return rx.image( + src=prompt, + decoding="async", + loading="lazy", + class_name="top-1/2 left-1/2 absolute rounded-lg w-[256px] md:w-[384px] lg:w-[512px] h-auto -translate-x-1/2 -translate-y-1/2 aspect-square", + ) + + +def index() -> rx.Component: + return rx.box( + input_bar(), + rx.box( + rx.foreach( + FluxState.images_list, + image_card, + ), + class_name="rounded-lg w-[256px] md:w-[384px] lg:w-[512px] h-[256px] md:h-[384px] lg:h-[512px] relative", + ), + rx.logo(), + rx.color_mode.button(position="top-right"), + class_name="relative flex flex-col justify-center items-center gap-6 bg-[--slate-2] mx-auto px-6 w-full h-screen font-['Instrument_Sans']", + ) + + +app = rx.App( + theme=rx.theme(accent_color="violet"), + head_components=[ + rx.el.link( + rel="preconnect", + href="https://fonts.googleapis.com", + ), + rx.el.link( + rel="preconnect", + href="https://fonts.gstatic.com", + crossorigin="", + ), + rx.el.link( + href="https://fonts.googleapis.com/css2?family=Instrument+Sans:ital,wght@0,400;0,500;0,600;0,700;1,400;1,500;1,600;1,700&display=swap", + rel="stylesheet", + ), + ], +) +app.add_page(index) diff --git a/flux-fast/requirements.txt b/flux-fast/requirements.txt new file mode 100644 index 00000000..cf36386b --- /dev/null +++ b/flux-fast/requirements.txt @@ -0,0 +1 @@ +reflex==0.6.3 \ No newline at end of file diff --git a/flux-fast/rxconfig.py b/flux-fast/rxconfig.py new file mode 100644 index 00000000..10b84ffe --- /dev/null +++ b/flux-fast/rxconfig.py @@ -0,0 +1,5 @@ +import reflex as rx + +config = rx.Config( + app_name="flux_fast", +) \ No newline at end of file