Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,14 +13,19 @@ GOOGLE_FONTS_API_KEY = os.environ.get("GOOGLE_FONTS_API_KEY")
|
|
| 13 |
|
| 14 |
st.set_page_config(page_title="Moodboard AI", layout="wide")
|
| 15 |
|
| 16 |
-
# --
|
| 17 |
if 'dark_mode' not in st.session_state:
|
| 18 |
st.session_state.dark_mode = False
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
|
|
|
|
| 21 |
if dark_mode_toggle != st.session_state.dark_mode:
|
| 22 |
st.session_state.dark_mode = dark_mode_toggle
|
| 23 |
-
st.
|
| 24 |
|
| 25 |
# -- Apply Dark Mode Styling --
|
| 26 |
if st.session_state.dark_mode:
|
|
@@ -56,7 +61,7 @@ else:
|
|
| 56 |
# -- Title --
|
| 57 |
st.title("π¨ Moodboard AI β Smart Visual Inspiration Generator")
|
| 58 |
|
| 59 |
-
# --
|
| 60 |
if UNSPLASH_ACCESS_KEY:
|
| 61 |
st.success("β
Unsplash API key loaded successfully.")
|
| 62 |
else:
|
|
@@ -70,14 +75,15 @@ else:
|
|
| 70 |
# -- Theme Input --
|
| 71 |
theme = st.text_input("Enter a theme or keyword (e.g. 'vintage tech', 'coastal minimalism'):", "futuristic tech").lower()
|
| 72 |
|
| 73 |
-
# --
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
st.
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
st.
|
|
|
|
| 81 |
|
| 82 |
# -- Fetch Images from Unsplash --
|
| 83 |
def fetch_images_from_unsplash(query, count=5):
|
|
@@ -131,7 +137,8 @@ def fetch_google_fonts():
|
|
| 131 |
# -- Show Moodboard --
|
| 132 |
if st.session_state.get("generate"):
|
| 133 |
with st.spinner("Generating your moodboard..."):
|
| 134 |
-
|
|
|
|
| 135 |
if not image_urls:
|
| 136 |
st.warning("No images found. Try another keyword or check your API key.")
|
| 137 |
else:
|
|
@@ -160,4 +167,4 @@ if st.session_state.get("generate"):
|
|
| 160 |
)
|
| 161 |
|
| 162 |
st.success("β
Moodboard ready! Right-click or screenshot to save.")
|
| 163 |
-
st.session_state.generate = False # Reset
|
|
|
|
| 13 |
|
| 14 |
st.set_page_config(page_title="Moodboard AI", layout="wide")
|
| 15 |
|
| 16 |
+
# -- Init Session State --
|
| 17 |
if 'dark_mode' not in st.session_state:
|
| 18 |
st.session_state.dark_mode = False
|
| 19 |
+
if 'generate' not in st.session_state:
|
| 20 |
+
st.session_state.generate = False
|
| 21 |
+
if 'remix' not in st.session_state:
|
| 22 |
+
st.session_state.remix = random.randint(1, 10000)
|
| 23 |
|
| 24 |
+
# -- Dark Mode Toggle (no forced rerun) --
|
| 25 |
+
dark_mode_toggle = st.toggle("π Toggle Dark Mode", value=st.session_state.dark_mode, key="dark_toggle")
|
| 26 |
if dark_mode_toggle != st.session_state.dark_mode:
|
| 27 |
st.session_state.dark_mode = dark_mode_toggle
|
| 28 |
+
st.experimental_rerun()
|
| 29 |
|
| 30 |
# -- Apply Dark Mode Styling --
|
| 31 |
if st.session_state.dark_mode:
|
|
|
|
| 61 |
# -- Title --
|
| 62 |
st.title("π¨ Moodboard AI β Smart Visual Inspiration Generator")
|
| 63 |
|
| 64 |
+
# -- API Status Display --
|
| 65 |
if UNSPLASH_ACCESS_KEY:
|
| 66 |
st.success("β
Unsplash API key loaded successfully.")
|
| 67 |
else:
|
|
|
|
| 75 |
# -- Theme Input --
|
| 76 |
theme = st.text_input("Enter a theme or keyword (e.g. 'vintage tech', 'coastal minimalism'):", "futuristic tech").lower()
|
| 77 |
|
| 78 |
+
# -- Control Buttons --
|
| 79 |
+
col1, col2 = st.columns(2)
|
| 80 |
+
with col1:
|
| 81 |
+
if st.button("π Remix Moodboard"):
|
| 82 |
+
st.session_state.remix = random.randint(1, 10000)
|
| 83 |
+
st.session_state.generate = True
|
| 84 |
+
with col2:
|
| 85 |
+
if st.button("β¨ Generate Moodboard"):
|
| 86 |
+
st.session_state.generate = True
|
| 87 |
|
| 88 |
# -- Fetch Images from Unsplash --
|
| 89 |
def fetch_images_from_unsplash(query, count=5):
|
|
|
|
| 137 |
# -- Show Moodboard --
|
| 138 |
if st.session_state.get("generate"):
|
| 139 |
with st.spinner("Generating your moodboard..."):
|
| 140 |
+
query = f"{theme} {st.session_state.remix}"
|
| 141 |
+
image_urls = fetch_images_from_unsplash(query)
|
| 142 |
if not image_urls:
|
| 143 |
st.warning("No images found. Try another keyword or check your API key.")
|
| 144 |
else:
|
|
|
|
| 167 |
)
|
| 168 |
|
| 169 |
st.success("β
Moodboard ready! Right-click or screenshot to save.")
|
| 170 |
+
st.session_state.generate = False # Reset
|