Update python.py
Browse files
python.py
CHANGED
|
@@ -45,25 +45,25 @@ def main():
|
|
| 45 |
"""
|
| 46 |
<style>
|
| 47 |
body {
|
| 48 |
-
background-color: #
|
| 49 |
}
|
| 50 |
.stTitle {
|
| 51 |
-
color: #
|
| 52 |
text-align: center;
|
| 53 |
font-family: 'Arial', sans-serif;
|
| 54 |
}
|
| 55 |
.stButton>button {
|
| 56 |
-
background-color: #
|
| 57 |
color: white;
|
| 58 |
border-radius: 8px;
|
| 59 |
}
|
| 60 |
.stDownloadButton>button {
|
| 61 |
-
background-color: #
|
| 62 |
color: white;
|
| 63 |
border-radius: 8px;
|
| 64 |
}
|
| 65 |
.stSlider {
|
| 66 |
-
color: #
|
| 67 |
}
|
| 68 |
</style>
|
| 69 |
""",
|
|
@@ -91,7 +91,7 @@ def main():
|
|
| 91 |
uploaded_file = st.file_uploader("๐ค Upload an Image", type=['jpg', 'jpeg', 'png'])
|
| 92 |
if uploaded_file:
|
| 93 |
image = Image.open(uploaded_file)
|
| 94 |
-
st.image(image, caption="Original Image",
|
| 95 |
|
| 96 |
st.subheader("๐๏ธ Transformation Controls")
|
| 97 |
|
|
@@ -102,32 +102,39 @@ def main():
|
|
| 102 |
)
|
| 103 |
|
| 104 |
# --- Default Transformations ---
|
|
|
|
|
|
|
| 105 |
if transformation_mode == "All Transformations":
|
| 106 |
st.write("### ๐ Adjust All Transformations")
|
| 107 |
|
| 108 |
# Translation
|
| 109 |
x_offset = st.slider("X Offset", -100, 100, 0)
|
| 110 |
y_offset = st.slider("Y Offset", -100, 100, 0)
|
| 111 |
-
|
|
|
|
| 112 |
|
| 113 |
# Rotation
|
| 114 |
angle = st.slider("Rotation Angle", 0, 360, 0)
|
| 115 |
-
|
|
|
|
| 116 |
|
| 117 |
# Scaling
|
| 118 |
scale = st.slider("Scale Factor", 0.5, 2.0, 1.0)
|
| 119 |
-
|
|
|
|
| 120 |
|
| 121 |
# Cropping
|
| 122 |
left = st.slider("Crop Left", 0, image.width, 0)
|
| 123 |
upper = st.slider("Crop Upper", 0, image.height, 0)
|
| 124 |
right = st.slider("Crop Right", left, image.width, image.width)
|
| 125 |
lower = st.slider("Crop Lower", upper, image.height, image.height)
|
| 126 |
-
|
|
|
|
| 127 |
|
| 128 |
# Flipping
|
| 129 |
flip_type = st.selectbox("Flip Image", ["None", "Horizontal", "Vertical"])
|
| 130 |
-
|
|
|
|
| 131 |
|
| 132 |
# --- Specific Transformation ---
|
| 133 |
elif transformation_mode == "Specific Transformation":
|
|
@@ -160,8 +167,8 @@ def main():
|
|
| 160 |
flip_type = st.selectbox("Flip Type", ["None", "Horizontal", "Vertical"])
|
| 161 |
image = flip_image(image, flip_type)
|
| 162 |
|
| 163 |
-
# --- Display Transformed Image ---
|
| 164 |
-
st.image(image, caption="Transformed Image",
|
| 165 |
|
| 166 |
# --- Download Transformed Image ---
|
| 167 |
img_buffer = io.BytesIO()
|
|
|
|
| 45 |
"""
|
| 46 |
<style>
|
| 47 |
body {
|
| 48 |
+
background-color: #F2D1B3; /* Soft nude beige */
|
| 49 |
}
|
| 50 |
.stTitle {
|
| 51 |
+
color: #5F3B26; /* Warm brown */
|
| 52 |
text-align: center;
|
| 53 |
font-family: 'Arial', sans-serif;
|
| 54 |
}
|
| 55 |
.stButton>button {
|
| 56 |
+
background-color: #D1A39A; /* Muted pinkish nude */
|
| 57 |
color: white;
|
| 58 |
border-radius: 8px;
|
| 59 |
}
|
| 60 |
.stDownloadButton>button {
|
| 61 |
+
background-color: #A87C61; /* Warm sand color */
|
| 62 |
color: white;
|
| 63 |
border-radius: 8px;
|
| 64 |
}
|
| 65 |
.stSlider {
|
| 66 |
+
color: #5F3B26; /* Warm brown */
|
| 67 |
}
|
| 68 |
</style>
|
| 69 |
""",
|
|
|
|
| 91 |
uploaded_file = st.file_uploader("๐ค Upload an Image", type=['jpg', 'jpeg', 'png'])
|
| 92 |
if uploaded_file:
|
| 93 |
image = Image.open(uploaded_file)
|
| 94 |
+
st.image(image, caption="Original Image", use_container_width=True)
|
| 95 |
|
| 96 |
st.subheader("๐๏ธ Transformation Controls")
|
| 97 |
|
|
|
|
| 102 |
)
|
| 103 |
|
| 104 |
# --- Default Transformations ---
|
| 105 |
+
transformed_image = image.copy() # Keep a copy for showing all intermediate transformations
|
| 106 |
+
|
| 107 |
if transformation_mode == "All Transformations":
|
| 108 |
st.write("### ๐ Adjust All Transformations")
|
| 109 |
|
| 110 |
# Translation
|
| 111 |
x_offset = st.slider("X Offset", -100, 100, 0)
|
| 112 |
y_offset = st.slider("Y Offset", -100, 100, 0)
|
| 113 |
+
translated_image = translate_image(transformed_image, x_offset, y_offset)
|
| 114 |
+
st.image(translated_image, caption="After Translation", use_container_width=True)
|
| 115 |
|
| 116 |
# Rotation
|
| 117 |
angle = st.slider("Rotation Angle", 0, 360, 0)
|
| 118 |
+
rotated_image = rotate_image(transformed_image, angle)
|
| 119 |
+
st.image(rotated_image, caption="After Rotation", use_container_width=True)
|
| 120 |
|
| 121 |
# Scaling
|
| 122 |
scale = st.slider("Scale Factor", 0.5, 2.0, 1.0)
|
| 123 |
+
scaled_image = scale_image(transformed_image, scale)
|
| 124 |
+
st.image(scaled_image, caption="After Scaling", use_container_width=True)
|
| 125 |
|
| 126 |
# Cropping
|
| 127 |
left = st.slider("Crop Left", 0, image.width, 0)
|
| 128 |
upper = st.slider("Crop Upper", 0, image.height, 0)
|
| 129 |
right = st.slider("Crop Right", left, image.width, image.width)
|
| 130 |
lower = st.slider("Crop Lower", upper, image.height, image.height)
|
| 131 |
+
cropped_image = crop_image(transformed_image, left, upper, right, lower)
|
| 132 |
+
st.image(cropped_image, caption="After Cropping", use_container_width=True)
|
| 133 |
|
| 134 |
# Flipping
|
| 135 |
flip_type = st.selectbox("Flip Image", ["None", "Horizontal", "Vertical"])
|
| 136 |
+
flipped_image = flip_image(transformed_image, flip_type)
|
| 137 |
+
st.image(flipped_image, caption="After Flipping", use_container_width=True)
|
| 138 |
|
| 139 |
# --- Specific Transformation ---
|
| 140 |
elif transformation_mode == "Specific Transformation":
|
|
|
|
| 167 |
flip_type = st.selectbox("Flip Type", ["None", "Horizontal", "Vertical"])
|
| 168 |
image = flip_image(image, flip_type)
|
| 169 |
|
| 170 |
+
# --- Display Final Transformed Image ---
|
| 171 |
+
st.image(image, caption="Transformed Image", use_container_width=True)
|
| 172 |
|
| 173 |
# --- Download Transformed Image ---
|
| 174 |
img_buffer = io.BytesIO()
|