Update app.py
Browse files
app.py
CHANGED
@@ -272,15 +272,24 @@ def process_image_with_prompt(image, prompt, model="o3-mini-high"):
|
|
272 |
except Exception as e:
|
273 |
return f"Error processing image with GPT: {str(e)}"
|
274 |
|
275 |
-
# ---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
276 |
def update_gallery():
|
277 |
all_files = get_gallery_files()
|
278 |
if all_files:
|
279 |
st.sidebar.subheader("Asset Gallery 📸📖")
|
280 |
cols = st.sidebar.columns(2)
|
281 |
-
|
282 |
-
|
283 |
-
#for idx, file in enumerate(all_files[:st.sidebar.slider("Gallery Size", 1, 10, 2)]):
|
284 |
with cols[idx % 2]:
|
285 |
st.session_state['unique_counter'] += 1
|
286 |
unique_id = st.session_state['unique_counter']
|
@@ -293,16 +302,23 @@ def update_gallery():
|
|
293 |
st.image(img, caption=os.path.basename(file), use_container_width=True)
|
294 |
doc.close()
|
295 |
checkbox_key = f"asset_{file}_{unique_id}"
|
296 |
-
st.session_state['asset_checkboxes'][file] = st.checkbox(
|
|
|
|
|
|
|
|
|
297 |
mime_type = "image/png" if file.endswith('.png') else "application/pdf"
|
298 |
st.markdown(get_download_link(file, mime_type, "Snag It! 📥"), unsafe_allow_html=True)
|
299 |
if st.button("Zap It! 🗑️", key=f"delete_{file}_{unique_id}"):
|
300 |
os.remove(file)
|
301 |
st.session_state['asset_checkboxes'].pop(file, None)
|
302 |
st.sidebar.success(f"Asset {os.path.basename(file)} vaporized! 💨")
|
303 |
-
st.
|
|
|
|
|
304 |
update_gallery()
|
305 |
|
|
|
306 |
# --- Sidebar Logs & History ---
|
307 |
st.sidebar.subheader("Action Logs 📜")
|
308 |
with st.sidebar:
|
@@ -511,7 +527,7 @@ with tab_build:
|
|
511 |
if entry not in st.session_state['history']:
|
512 |
st.session_state['history'].append(entry)
|
513 |
st.success(f"Model downloaded and saved to {config.model_path}! 🎉")
|
514 |
-
st.
|
515 |
|
516 |
# === Tab: Test Image Gen (existing) ===
|
517 |
with tab_imggen:
|
|
|
272 |
except Exception as e:
|
273 |
return f"Error processing image with GPT: {str(e)}"
|
274 |
|
275 |
+
# --- Sidebar Setup (Add this near the top, before tabs) ---
|
276 |
+
st.sidebar.subheader("Gallery Settings")
|
277 |
+
if 'gallery_size' not in st.session_state:
|
278 |
+
st.session_state['gallery_size'] = 2 # Default value
|
279 |
+
st.session_state['gallery_size'] = st.sidebar.slider(
|
280 |
+
"Gallery Size",
|
281 |
+
1, 10, st.session_state['gallery_size'],
|
282 |
+
key="gallery_size_slider" # Unique key for the slider
|
283 |
+
)
|
284 |
+
|
285 |
+
# --- Updated Gallery Function ---
|
286 |
def update_gallery():
|
287 |
all_files = get_gallery_files()
|
288 |
if all_files:
|
289 |
st.sidebar.subheader("Asset Gallery 📸📖")
|
290 |
cols = st.sidebar.columns(2)
|
291 |
+
# Use the stored gallery size from session state
|
292 |
+
for idx, file in enumerate(all_files[:st.session_state['gallery_size']]):
|
|
|
293 |
with cols[idx % 2]:
|
294 |
st.session_state['unique_counter'] += 1
|
295 |
unique_id = st.session_state['unique_counter']
|
|
|
302 |
st.image(img, caption=os.path.basename(file), use_container_width=True)
|
303 |
doc.close()
|
304 |
checkbox_key = f"asset_{file}_{unique_id}"
|
305 |
+
st.session_state['asset_checkboxes'][file] = st.checkbox(
|
306 |
+
"Use for SFT/Input",
|
307 |
+
value=st.session_state['asset_checkboxes'].get(file, False),
|
308 |
+
key=checkbox_key
|
309 |
+
)
|
310 |
mime_type = "image/png" if file.endswith('.png') else "application/pdf"
|
311 |
st.markdown(get_download_link(file, mime_type, "Snag It! 📥"), unsafe_allow_html=True)
|
312 |
if st.button("Zap It! 🗑️", key=f"delete_{file}_{unique_id}"):
|
313 |
os.remove(file)
|
314 |
st.session_state['asset_checkboxes'].pop(file, None)
|
315 |
st.sidebar.success(f"Asset {os.path.basename(file)} vaporized! 💨")
|
316 |
+
st.rerun()
|
317 |
+
|
318 |
+
# Call update_gallery() once initially or after actions as needed
|
319 |
update_gallery()
|
320 |
|
321 |
+
|
322 |
# --- Sidebar Logs & History ---
|
323 |
st.sidebar.subheader("Action Logs 📜")
|
324 |
with st.sidebar:
|
|
|
527 |
if entry not in st.session_state['history']:
|
528 |
st.session_state['history'].append(entry)
|
529 |
st.success(f"Model downloaded and saved to {config.model_path}! 🎉")
|
530 |
+
st.rerun()
|
531 |
|
532 |
# === Tab: Test Image Gen (existing) ===
|
533 |
with tab_imggen:
|