Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -58,12 +58,14 @@ if uploaded_files:
|
|
| 58 |
continue
|
| 59 |
|
| 60 |
# --- Advanced Mode ---
|
|
|
|
| 61 |
key_cropped = f"cropped_{idx}"
|
| 62 |
key_preview = f"preview_{idx}"
|
| 63 |
key_final = f"final_{idx}"
|
| 64 |
key_angle = f"angle_{idx}"
|
| 65 |
|
| 66 |
-
if
|
|
|
|
| 67 |
st.session_state[key_cropped] = resized.copy()
|
| 68 |
st.session_state[key_preview] = resized.copy()
|
| 69 |
st.session_state[key_final] = None
|
|
@@ -71,20 +73,20 @@ if uploaded_files:
|
|
| 71 |
|
| 72 |
with st.expander("✂️ Crop, Enhance & Rotate", expanded=True):
|
| 73 |
# Step 1: Crop
|
| 74 |
-
cropped = crop_with_sliders(
|
| 75 |
st.session_state[key_cropped] = cropped
|
| 76 |
|
| 77 |
-
# Step 2:
|
| 78 |
col1, col2, col3 = st.columns(3)
|
| 79 |
|
| 80 |
with col1:
|
| 81 |
if st.button("🔁 Reset", key=f"reset_{idx}"):
|
| 82 |
-
st.session_state[key_preview] =
|
| 83 |
st.session_state[key_angle] = 0
|
| 84 |
|
| 85 |
with col2:
|
| 86 |
if st.button("✨ Enhance", key=f"enhance_{idx}"):
|
| 87 |
-
enhancer = ImageEnhance.Contrast(
|
| 88 |
sharp = ImageEnhance.Sharpness(enhancer.enhance(1.5))
|
| 89 |
st.session_state[key_preview] = sharp.enhance(2.0)
|
| 90 |
|
|
|
|
| 58 |
continue
|
| 59 |
|
| 60 |
# --- Advanced Mode ---
|
| 61 |
+
key_base = f"base_{idx}"
|
| 62 |
key_cropped = f"cropped_{idx}"
|
| 63 |
key_preview = f"preview_{idx}"
|
| 64 |
key_final = f"final_{idx}"
|
| 65 |
key_angle = f"angle_{idx}"
|
| 66 |
|
| 67 |
+
if key_base not in st.session_state:
|
| 68 |
+
st.session_state[key_base] = resized.copy()
|
| 69 |
st.session_state[key_cropped] = resized.copy()
|
| 70 |
st.session_state[key_preview] = resized.copy()
|
| 71 |
st.session_state[key_final] = None
|
|
|
|
| 73 |
|
| 74 |
with st.expander("✂️ Crop, Enhance & Rotate", expanded=True):
|
| 75 |
# Step 1: Crop
|
| 76 |
+
cropped = crop_with_sliders(st.session_state[key_base], key_prefix=f"img_{idx}")
|
| 77 |
st.session_state[key_cropped] = cropped
|
| 78 |
|
| 79 |
+
# Step 2: Rotate + Enhance + Reset
|
| 80 |
col1, col2, col3 = st.columns(3)
|
| 81 |
|
| 82 |
with col1:
|
| 83 |
if st.button("🔁 Reset", key=f"reset_{idx}"):
|
| 84 |
+
st.session_state[key_preview] = st.session_state[key_base].copy()
|
| 85 |
st.session_state[key_angle] = 0
|
| 86 |
|
| 87 |
with col2:
|
| 88 |
if st.button("✨ Enhance", key=f"enhance_{idx}"):
|
| 89 |
+
enhancer = ImageEnhance.Contrast(st.session_state[key_cropped])
|
| 90 |
sharp = ImageEnhance.Sharpness(enhancer.enhance(1.5))
|
| 91 |
st.session_state[key_preview] = sharp.enhance(2.0)
|
| 92 |
|