Spaces:
Build error
Build error
Merge branch 'main' of https://huggingface.co/spaces/yash-gupta-01/machineLearning
Browse files- home.py +1 -1
- pages/image_augmentation.py +183 -0
- pages/life_cycle_of_ml_project.py +65 -0
home.py
CHANGED
|
@@ -134,4 +134,4 @@ st.markdown("""
|
|
| 134 |
<footer>
|
| 135 |
<p>Made with ❤️ by <strong>Yash Harish Gupta</strong> | © 2024</p>
|
| 136 |
</footer>
|
| 137 |
-
""", unsafe_allow_html=True)
|
|
|
|
| 134 |
<footer>
|
| 135 |
<p>Made with ❤️ by <strong>Yash Harish Gupta</strong> | © 2024</p>
|
| 136 |
</footer>
|
| 137 |
+
""", unsafe_allow_html=True)
|
pages/image_augmentation.py
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from PIL import Image, ImageOps
|
| 3 |
+
import numpy as np
|
| 4 |
+
import io
|
| 5 |
+
|
| 6 |
+
# Improved App Styling
|
| 7 |
+
st.set_page_config(
|
| 8 |
+
page_title="Modern Image Augmentation",
|
| 9 |
+
page_icon="✨",
|
| 10 |
+
layout="wide",
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
# Custom CSS for modern look
|
| 14 |
+
st.markdown(
|
| 15 |
+
"""
|
| 16 |
+
<style>
|
| 17 |
+
/* App Background */
|
| 18 |
+
.stApp {
|
| 19 |
+
background: linear-gradient(135deg, #1f1f1f, #000000);
|
| 20 |
+
color: #ffffff;
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
/* Title Styling */
|
| 24 |
+
h1 {
|
| 25 |
+
text-align: center;
|
| 26 |
+
color: #00ffcc;
|
| 27 |
+
font-family: 'Arial Black', sans-serif;
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
/* Sidebar Styling */
|
| 31 |
+
[data-testid="stSidebar"] {
|
| 32 |
+
background-color: #1c1c1c;
|
| 33 |
+
border-right: 2px solid #00ffcc;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
/* Slider Styling */
|
| 37 |
+
[class^="css-qbe2hs"] {
|
| 38 |
+
color: #00ffcc !important;
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
/* Buttons */
|
| 42 |
+
button {
|
| 43 |
+
background-color: #00ffcc !important;
|
| 44 |
+
border: none;
|
| 45 |
+
font-weight: bold;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
button:hover {
|
| 49 |
+
background-color: #00e6b8 !important;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
/* Image Uploader */
|
| 53 |
+
[data-testid="stFileUploadDropzone"] {
|
| 54 |
+
background: #1c1c1c;
|
| 55 |
+
border: 2px dashed #00ffcc;
|
| 56 |
+
border-radius: 10px;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
/* Augmentation Options Styling */
|
| 60 |
+
[class^="stRadio"] > div > label {
|
| 61 |
+
color: #ffffff;
|
| 62 |
+
}
|
| 63 |
+
</style>
|
| 64 |
+
""",
|
| 65 |
+
unsafe_allow_html=True,
|
| 66 |
+
)
|
| 67 |
+
|
| 68 |
+
st.title("✨ Modern Image Data Augmentation ✨")
|
| 69 |
+
|
| 70 |
+
# File uploader for image
|
| 71 |
+
uploaded_image = st.file_uploader("Upload an Image to Get Started", type=["jpg", "png", "jpeg"])
|
| 72 |
+
|
| 73 |
+
if uploaded_image:
|
| 74 |
+
try:
|
| 75 |
+
image = Image.open(uploaded_image)
|
| 76 |
+
col1, col2 = st.columns(2)
|
| 77 |
+
|
| 78 |
+
# Display original image
|
| 79 |
+
with col1:
|
| 80 |
+
st.subheader("Original Image")
|
| 81 |
+
st.image(image, caption="Uploaded Image", use_container_width=True)
|
| 82 |
+
|
| 83 |
+
st.subheader("✨ Select an Augmentation")
|
| 84 |
+
|
| 85 |
+
# Augmentation options
|
| 86 |
+
augmentation_option = st.radio(
|
| 87 |
+
"Choose an Augmentation Type:",
|
| 88 |
+
[
|
| 89 |
+
"None",
|
| 90 |
+
"Cropping",
|
| 91 |
+
"Flipping",
|
| 92 |
+
"Rotation",
|
| 93 |
+
"Zooming In",
|
| 94 |
+
"Zooming Out",
|
| 95 |
+
"Translation",
|
| 96 |
+
"Shearing",
|
| 97 |
+
],
|
| 98 |
+
)
|
| 99 |
+
|
| 100 |
+
augmented_image = image
|
| 101 |
+
|
| 102 |
+
# Augmentation Logic
|
| 103 |
+
if augmentation_option == "Cropping":
|
| 104 |
+
st.info("Adjust the crop sliders to modify the image.")
|
| 105 |
+
left = st.slider("Left Crop", 0, image.width // 2, 0)
|
| 106 |
+
top = st.slider("Top Crop", 0, image.height // 2, 0)
|
| 107 |
+
right = st.slider("Right Crop", 0, image.width // 2, 0)
|
| 108 |
+
bottom = st.slider("Bottom Crop", 0, image.height // 2, 0)
|
| 109 |
+
augmented_image = image.crop((left, top, image.width - right, image.height - bottom))
|
| 110 |
+
|
| 111 |
+
elif augmentation_option == "Flipping":
|
| 112 |
+
flip_option = st.selectbox("Choose Flip Type", ["Horizontal", "Vertical"])
|
| 113 |
+
if flip_option == "Horizontal":
|
| 114 |
+
augmented_image = ImageOps.mirror(image)
|
| 115 |
+
elif flip_option == "Vertical":
|
| 116 |
+
augmented_image = ImageOps.flip(image)
|
| 117 |
+
|
| 118 |
+
elif augmentation_option == "Rotation":
|
| 119 |
+
rotation_angle = st.slider("Rotation Angle (°)", 0, 360, 0)
|
| 120 |
+
if rotation_angle:
|
| 121 |
+
augmented_image = image.rotate(rotation_angle, expand=True)
|
| 122 |
+
|
| 123 |
+
elif augmentation_option == "Zooming In":
|
| 124 |
+
zoom_factor = st.slider("Zoom Factor (%)", 100, 200, 100) / 100.0
|
| 125 |
+
if zoom_factor != 1.0:
|
| 126 |
+
width, height = image.size
|
| 127 |
+
new_width = int(width * zoom_factor)
|
| 128 |
+
new_height = int(height * zoom_factor)
|
| 129 |
+
zoomed_image = image.resize((new_width, new_height))
|
| 130 |
+
augmented_image = zoomed_image.crop(((new_width - width) // 2, (new_height - height) // 2,
|
| 131 |
+
(new_width + width) // 2, (new_height + height) // 2))
|
| 132 |
+
|
| 133 |
+
elif augmentation_option == "Zooming Out":
|
| 134 |
+
zoom_factor = st.slider("Zoom Factor (%)", 50, 100, 100) / 100.0
|
| 135 |
+
if zoom_factor != 1.0:
|
| 136 |
+
width, height = image.size
|
| 137 |
+
new_width = int(width * zoom_factor)
|
| 138 |
+
new_height = int(height * zoom_factor)
|
| 139 |
+
zoomed_image = image.resize((new_width, new_height))
|
| 140 |
+
padded_image = Image.new("RGB", (width, height), (0, 0, 0)) # Black padding
|
| 141 |
+
padded_image.paste(zoomed_image, ((width - new_width) // 2, (height - new_height) // 2))
|
| 142 |
+
augmented_image = padded_image
|
| 143 |
+
|
| 144 |
+
elif augmentation_option == "Translation":
|
| 145 |
+
translation_x = st.slider("Horizontal Shift (Pixels)", -100, 100, 0)
|
| 146 |
+
translation_y = st.slider("Vertical Shift (Pixels)", -100, 100, 0)
|
| 147 |
+
if translation_x or translation_y:
|
| 148 |
+
translation_matrix = (1, 0, translation_x, 0, 1, translation_y)
|
| 149 |
+
augmented_image = image.transform(
|
| 150 |
+
image.size, Image.AFFINE, translation_matrix, fillcolor=(0, 0, 0)
|
| 151 |
+
)
|
| 152 |
+
|
| 153 |
+
elif augmentation_option == "Shearing":
|
| 154 |
+
shear_angle = st.slider("Shearing Angle (°)", -45, 45, 0)
|
| 155 |
+
if shear_angle:
|
| 156 |
+
shear_matrix = (1, np.tan(np.radians(shear_angle)), 0, 0, 1, 0)
|
| 157 |
+
augmented_image = image.transform(
|
| 158 |
+
(image.width + abs(int(image.height * np.tan(np.radians(shear_angle)))), image.height),
|
| 159 |
+
Image.AFFINE,
|
| 160 |
+
shear_matrix,
|
| 161 |
+
fillcolor=(0, 0, 0),
|
| 162 |
+
)
|
| 163 |
+
|
| 164 |
+
# Display Augmented Image
|
| 165 |
+
with col2:
|
| 166 |
+
st.subheader(f"{augmentation_option} Applied")
|
| 167 |
+
st.image(augmented_image, caption="Augmented Image", use_container_width=True)
|
| 168 |
+
|
| 169 |
+
# Download button
|
| 170 |
+
buffer = io.BytesIO()
|
| 171 |
+
augmented_image.save(buffer, format="PNG")
|
| 172 |
+
buffer.seek(0)
|
| 173 |
+
st.download_button(
|
| 174 |
+
"🎉 Download Augmented Image 🎉",
|
| 175 |
+
buffer,
|
| 176 |
+
file_name="augmented_image.png",
|
| 177 |
+
mime="image/png",
|
| 178 |
+
)
|
| 179 |
+
|
| 180 |
+
except Exception as e:
|
| 181 |
+
st.error(f"An error occurred: {e}")
|
| 182 |
+
else:
|
| 183 |
+
st.warning("Please upload an image to begin.")
|
pages/life_cycle_of_ml_project.py
CHANGED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<<<<<<< HEAD
|
| 2 |
+
=======
|
| 3 |
+
import matplotlib.pyplot as plt
|
| 4 |
+
import numpy as np
|
| 5 |
+
|
| 6 |
+
def draw_lifecycle_diagram():
|
| 7 |
+
# Labels and colors for the lifecycle phases
|
| 8 |
+
labels = [
|
| 9 |
+
"1. Gathering Data",
|
| 10 |
+
"2. Data Preparation",
|
| 11 |
+
"3. Data Wrangling",
|
| 12 |
+
"4. Analyze Data",
|
| 13 |
+
"5. Train Model",
|
| 14 |
+
"6. Test Model",
|
| 15 |
+
"7. Deployment"
|
| 16 |
+
]
|
| 17 |
+
colors = [
|
| 18 |
+
"#3CB371", "#8FBC8F", "#00CED1", "#1E90FF",
|
| 19 |
+
"#6A5ACD", "#FF8C00", "#DC143C"
|
| 20 |
+
]
|
| 21 |
+
|
| 22 |
+
# Create a figure and axis with equal aspect ratio
|
| 23 |
+
fig, ax = plt.subplots(figsize=(9, 9), subplot_kw={"aspect": "equal"})
|
| 24 |
+
size = 0.3 # Width of the pie sections
|
| 25 |
+
|
| 26 |
+
# Create pie sections for the lifecycle phases
|
| 27 |
+
wedges, _ = ax.pie(
|
| 28 |
+
[1] * len(labels),
|
| 29 |
+
colors=colors,
|
| 30 |
+
radius=1,
|
| 31 |
+
startangle=90,
|
| 32 |
+
wedgeprops=dict(width=size, edgecolor='w')
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
# Add text labels around the circle
|
| 36 |
+
for i, wedge in enumerate(wedges):
|
| 37 |
+
# Calculate the angle for the label placement
|
| 38 |
+
angle = (wedge.theta2 - wedge.theta1) / 2.0 + wedge.theta1
|
| 39 |
+
x = np.cos(np.deg2rad(angle))
|
| 40 |
+
y = np.sin(np.deg2rad(angle))
|
| 41 |
+
|
| 42 |
+
# Add label text
|
| 43 |
+
ax.text(
|
| 44 |
+
1.2 * x, 1.2 * y, labels[i],
|
| 45 |
+
ha="center", va="center", fontsize=10, weight="bold",
|
| 46 |
+
bbox=dict(boxstyle="round,pad=0.3", facecolor=colors[i], edgecolor="w")
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
+
# Add center text with a descriptive title
|
| 50 |
+
ax.text(
|
| 51 |
+
0, 0, "Machine Learning\nLifecycle",
|
| 52 |
+
ha="center", va="center", fontsize=16, weight="bold", color="black",
|
| 53 |
+
bbox=dict(boxstyle="round,pad=0.5", facecolor="white", edgecolor="black")
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
# Clean up the diagram style
|
| 57 |
+
ax.set(aspect="equal", xticks=[], yticks=[], title="Machine Learning Lifecycle")
|
| 58 |
+
return fig
|
| 59 |
+
|
| 60 |
+
# Save the diagram or display it in Streamlit
|
| 61 |
+
if __name__ == "__main__":
|
| 62 |
+
# Display the diagram
|
| 63 |
+
fig = draw_lifecycle_diagram()
|
| 64 |
+
plt.show()
|
| 65 |
+
>>>>>>> 8f9a0e1fa29de18412c739d9d5c3da24894df34d
|