renderfy commited on
Commit
c08826a
·
verified ·
1 Parent(s): f088758

Upload streamlit_app.py

Browse files
Files changed (1) hide show
  1. streamlit_app.py +33 -26
streamlit_app.py CHANGED
@@ -1,4 +1,4 @@
1
- # streamlit_app.py — AI LightBox · Jewelry (dark-orange UI)
2
  # Pre-run sabit 4 kart (Input/Packshot/Padded/Video loop) + Run sonrası native odaklı kartlar
3
 
4
  import os, io, base64, zipfile, requests, streamlit as st
@@ -158,23 +158,18 @@ def inject_base_css():
158
  /* Info/Warning boxes tweak */
159
  .stAlert { border-radius: 10px; }
160
 
161
- /* Inputs container subtle borders */
162
- .stSelectbox, .stTextInput, .stNumberInput, .stFileUploader, .stCheckbox, .stSlider, .stRadio {
163
- --border-color: rgba(255,255,255,0.08);
164
- }
165
-
166
  /* Card titles */
167
  .lb-card-title {
168
  font-weight: 700; font-size: 1.05rem; margin: 2px 0 8px 0; color: #eaecef;
169
  }
170
 
171
- /* Frames: FIX white band make them dark and subtle outline */
172
  .lb-frame {
173
  position: relative; width: 100%;
174
  border-radius: 12px; overflow: hidden;
175
- background: #111419; /* dark, not white */
176
  display:flex; align-items:center; justify-content:center;
177
- box-shadow: 0 0 0 1px rgba(255,122,26,0.15) inset; /* orange-tinted inner border */
178
  }
179
  .lb-frame img { width:100%; height:100%; display:block; }
180
 
@@ -571,28 +566,40 @@ if res:
571
  mime="video/mp4", key=f"job{st.session_state['job_counter']}_video_dl")
572
  else:
573
  c_vid.markdown('<div class="lb-frame"></div>', unsafe_allow_html=True)
574
- if st.checkbox("Generate Video From This Result", value=False, key="video_toggle"):
 
 
 
575
  src_for_video = res.get("placed_native_url") or res.get("packshot_native_url")
576
  if not src_for_video:
577
  st.warning("Video için kullanılacak native görsel bulunamadı.")
578
  else:
579
  with st.spinner("Generating Video …"):
580
- v = post_video(
581
- src_for_video,
582
- duration=st.session_state.get("duration_sel", VIDEO_DUR_OPTIONS[0]),
583
- resolution=st.session_state.get("resolution_sel", VIDEO_RES_OPTIONS[1]),
584
- preview_aspect=st.session_state.get("preview_aspect","9:16"),
585
- prompt_optimizer=False,
586
- )
587
- vurl2 = (v.get("result") or {}).get("video", {}).get("url")
588
- ui_hints = v.get("ui_hints") or {}
589
- if vurl2:
590
- st.session_state["results"]["video_url"] = vurl2
591
- if isinstance(ui_hints, dict):
592
- st.session_state["video_ui_max_px"] = int(ui_hints.get("suggested_video_max_px", VIDEO_MAX_PX_DEFAULT))
593
- st.success("Video is Ready!.")
594
- else:
595
- st.info("Video URL gelmedi.")
 
 
 
 
 
 
 
 
 
596
 
597
  # Native ZIP
598
  named = []
 
1
+ # streamlit_app.py — AI LightBox · Jewelry (dark-orange UI, fixed video refresh)
2
  # Pre-run sabit 4 kart (Input/Packshot/Padded/Video loop) + Run sonrası native odaklı kartlar
3
 
4
  import os, io, base64, zipfile, requests, streamlit as st
 
158
  /* Info/Warning boxes tweak */
159
  .stAlert { border-radius: 10px; }
160
 
 
 
 
 
 
161
  /* Card titles */
162
  .lb-card-title {
163
  font-weight: 700; font-size: 1.05rem; margin: 2px 0 8px 0; color: #eaecef;
164
  }
165
 
166
+ /* Frames: dark background to avoid white band over title */
167
  .lb-frame {
168
  position: relative; width: 100%;
169
  border-radius: 12px; overflow: hidden;
170
+ background: #111419;
171
  display:flex; align-items:center; justify-content:center;
172
+ box-shadow: 0 0 0 1px rgba(255,122,26,0.15) inset;
173
  }
174
  .lb-frame img { width:100%; height:100%; display:block; }
175
 
 
566
  mime="video/mp4", key=f"job{st.session_state['job_counter']}_video_dl")
567
  else:
568
  c_vid.markdown('<div class="lb-frame"></div>', unsafe_allow_html=True)
569
+ # ---- Generate video on demand ----
570
+ # unique key by job to avoid stale checkbox value on rerun
571
+ vid_checkbox_key = f"video_toggle_job{st.session_state['job_counter']}"
572
+ if st.checkbox("Generate Video From This Result", value=False, key=vid_checkbox_key):
573
  src_for_video = res.get("placed_native_url") or res.get("packshot_native_url")
574
  if not src_for_video:
575
  st.warning("Video için kullanılacak native görsel bulunamadı.")
576
  else:
577
  with st.spinner("Generating Video …"):
578
+ try:
579
+ v = post_video(
580
+ src_for_video,
581
+ duration=st.session_state.get("duration_sel", VIDEO_DUR_OPTIONS[0]),
582
+ resolution=st.session_state.get("resolution_sel", VIDEO_RES_OPTIONS[1]),
583
+ preview_aspect=st.session_state.get("preview_aspect","9:16"),
584
+ prompt_optimizer=False,
585
+ )
586
+ except requests.HTTPError as e:
587
+ st.error(f"HTTP {e.response.status_code}")
588
+ v = None
589
+ if v:
590
+ vurl2 = (v.get("result") or {}).get("video", {}).get("url")
591
+ ui_hints = v.get("ui_hints") or {}
592
+ if vurl2:
593
+ # write to session and force rerun so the video appears immediately
594
+ st.session_state["results"]["video_url"] = vurl2
595
+ if isinstance(ui_hints, dict):
596
+ st.session_state["video_ui_max_px"] = int(ui_hints.get("suggested_video_max_px", VIDEO_MAX_PX_DEFAULT))
597
+ # reset checkbox before rerun to prevent re-trigger loop
598
+ st.session_state.pop(vid_checkbox_key, None)
599
+ st.success("Video is Ready! Showing preview…")
600
+ st.rerun()
601
+ else:
602
+ st.info("Video URL gelmedi.")
603
 
604
  # Native ZIP
605
  named = []