Update pages/Life_cycle_of_ML.py
Browse files- pages/Life_cycle_of_ML.py +74 -79
pages/Life_cycle_of_ML.py
CHANGED
|
@@ -813,19 +813,12 @@ def affine_transformation_demo():
|
|
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
-
# Function to handle the drawing
|
| 817 |
def draw_shapes_on_canvas():
|
| 818 |
-
# Global variables for drawing state
|
| 819 |
-
drawing = False
|
| 820 |
-
start_point = (-1, -1)
|
| 821 |
-
end_point = (-1, -1)
|
| 822 |
-
polygon_points = []
|
| 823 |
-
|
| 824 |
# Streamlit UI for shape selection and canvas size
|
| 825 |
-
st.title('Interactive Shape Drawing
|
| 826 |
|
| 827 |
# Shape selection dropdown
|
| 828 |
-
current_shape = st.selectbox("Select Shape", ["Line", "Rectangle", "Circle", "Polygon"])
|
| 829 |
|
| 830 |
# Display canvas size options
|
| 831 |
width = st.slider('Canvas Width', min_value=100, max_value=1000, value=500)
|
|
@@ -834,76 +827,78 @@ def draw_shapes_on_canvas():
|
|
| 834 |
# Create canvas
|
| 835 |
canvas = np.ones((height, width, 3), dtype=np.uint8) * 255 # White canvas
|
| 836 |
|
| 837 |
-
#
|
| 838 |
-
if
|
| 839 |
-
st.
|
| 840 |
-
|
| 841 |
-
|
| 842 |
-
|
| 843 |
-
|
| 844 |
-
|
| 845 |
-
|
| 846 |
-
|
| 847 |
-
|
| 848 |
-
|
| 849 |
-
|
| 850 |
-
|
| 851 |
-
|
| 852 |
-
|
| 853 |
-
|
| 854 |
-
|
| 855 |
-
|
| 856 |
-
|
| 857 |
-
|
| 858 |
-
|
| 859 |
-
|
| 860 |
-
|
| 861 |
-
|
| 862 |
-
|
| 863 |
-
|
| 864 |
-
|
| 865 |
-
|
| 866 |
-
|
| 867 |
-
|
| 868 |
-
|
| 869 |
-
|
| 870 |
-
|
| 871 |
-
|
| 872 |
-
|
| 873 |
-
|
| 874 |
-
|
| 875 |
-
|
| 876 |
-
|
| 877 |
-
|
| 878 |
-
|
| 879 |
-
|
| 880 |
-
|
| 881 |
-
|
| 882 |
-
|
| 883 |
-
|
| 884 |
-
|
| 885 |
-
|
| 886 |
-
|
| 887 |
-
|
| 888 |
-
|
| 889 |
-
|
| 890 |
-
|
| 891 |
-
|
| 892 |
-
|
| 893 |
-
|
| 894 |
-
|
| 895 |
-
|
| 896 |
-
|
| 897 |
-
|
| 898 |
-
st.
|
| 899 |
-
|
| 900 |
-
|
| 901 |
-
|
| 902 |
-
|
| 903 |
-
|
| 904 |
-
|
| 905 |
-
|
| 906 |
-
|
|
|
|
|
|
|
| 907 |
|
| 908 |
|
| 909 |
if 'page' not in st.session_state:
|
|
|
|
| 813 |
|
| 814 |
|
| 815 |
|
|
|
|
| 816 |
def draw_shapes_on_canvas():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 817 |
# Streamlit UI for shape selection and canvas size
|
| 818 |
+
st.title('Interactive Shape Drawing & Animation')
|
| 819 |
|
| 820 |
# Shape selection dropdown
|
| 821 |
+
current_shape = st.selectbox("Select Shape", ["Line", "Rectangle", "Circle", "Polygon", "Text"])
|
| 822 |
|
| 823 |
# Display canvas size options
|
| 824 |
width = st.slider('Canvas Width', min_value=100, max_value=1000, value=500)
|
|
|
|
| 827 |
# Create canvas
|
| 828 |
canvas = np.ones((height, width, 3), dtype=np.uint8) * 255 # White canvas
|
| 829 |
|
| 830 |
+
# Parameters for drawing shapes
|
| 831 |
+
if current_shape == "Line":
|
| 832 |
+
start_point = (st.slider("Line Start X", 0, width, 0), st.slider("Line Start Y", 0, height, 0))
|
| 833 |
+
end_point = (st.slider("Line End X", 0, width, 200), st.slider("Line End Y", 0, height, 0))
|
| 834 |
+
line_color = st.color_picker("Line Color", "#b4b4b4")
|
| 835 |
+
thickness = st.slider("Line Thickness", 1, 10, 2)
|
| 836 |
+
|
| 837 |
+
# Convert color from Hex to BGR
|
| 838 |
+
line_color_bgr = tuple(int(line_color[i:i+2], 16) for i in (5, 3, 1))
|
| 839 |
+
|
| 840 |
+
# Draw Line
|
| 841 |
+
cv2.line(canvas, start_point, end_point, line_color_bgr, thickness)
|
| 842 |
+
|
| 843 |
+
elif current_shape == "Rectangle":
|
| 844 |
+
top_left = (st.slider("Top-left X", 0, width, 200), st.slider("Top-left Y", 0, height, 200))
|
| 845 |
+
bottom_right = (st.slider("Bottom-right X", 0, width, 500), st.slider("Bottom-right Y", 0, height, 400))
|
| 846 |
+
rect_color = st.color_picker("Rectangle Color", "#ff0000")
|
| 847 |
+
rect_thickness = st.slider("Rectangle Thickness", 1, 10, 2)
|
| 848 |
+
|
| 849 |
+
# Convert color from Hex to BGR
|
| 850 |
+
rect_color_bgr = tuple(int(rect_color[i:i+2], 16) for i in (5, 3, 1))
|
| 851 |
+
|
| 852 |
+
# Draw Rectangle
|
| 853 |
+
cv2.rectangle(canvas, top_left, bottom_right, rect_color_bgr, rect_thickness)
|
| 854 |
+
|
| 855 |
+
elif current_shape == "Circle":
|
| 856 |
+
center = (st.slider("Center X", 0, width, 250), st.slider("Center Y", 0, height, 250))
|
| 857 |
+
radius = st.slider("Circle Radius", 10, min(width, height)//2, 150)
|
| 858 |
+
circle_color = st.color_picker("Circle Color", "#00ff00")
|
| 859 |
+
circle_thickness = st.slider("Circle Thickness", 1, 10, 2)
|
| 860 |
+
|
| 861 |
+
# Convert color from Hex to BGR
|
| 862 |
+
circle_color_bgr = tuple(int(circle_color[i:i+2], 16) for i in (5, 3, 1))
|
| 863 |
+
|
| 864 |
+
# Draw Circle
|
| 865 |
+
cv2.circle(canvas, center, radius, circle_color_bgr, circle_thickness)
|
| 866 |
+
|
| 867 |
+
elif current_shape == "Polygon":
|
| 868 |
+
# Define points for the polygon
|
| 869 |
+
polygon_points = []
|
| 870 |
+
for i in range(5):
|
| 871 |
+
x = st.slider(f"Polygon Point {i+1} X", 0, width, 100 + i*50)
|
| 872 |
+
y = st.slider(f"Polygon Point {i+1} Y", 0, height, 100 + i*50)
|
| 873 |
+
polygon_points.append((x, y))
|
| 874 |
+
|
| 875 |
+
polygon_color = st.color_picker("Polygon Color", "#00ff00")
|
| 876 |
+
polygon_thickness = st.slider("Polygon Thickness", 1, 10, 2)
|
| 877 |
+
|
| 878 |
+
# Convert color from Hex to BGR
|
| 879 |
+
polygon_color_bgr = tuple(int(polygon_color[i:i+2], 16) for i in (5, 3, 1))
|
| 880 |
+
|
| 881 |
+
# Draw Polygon
|
| 882 |
+
pts = np.array(polygon_points, np.int32)
|
| 883 |
+
pts = pts.reshape((-1, 1, 2))
|
| 884 |
+
cv2.polylines(canvas, [pts], True, polygon_color_bgr, polygon_thickness)
|
| 885 |
+
|
| 886 |
+
elif current_shape == "Text":
|
| 887 |
+
text = st.text_input("Text to display", "SaniyaMastan")
|
| 888 |
+
font = cv2.FONT_ITALIC
|
| 889 |
+
font_size = st.slider("Font Size", 1, 5, 2)
|
| 890 |
+
text_color = st.color_picker("Text Color", "#ff0000")
|
| 891 |
+
text_thickness = st.slider("Text Thickness", 1, 10, 2)
|
| 892 |
+
text_position = (st.slider("Text Position X", 0, width, 100), st.slider("Text Position Y", 0, height, 100))
|
| 893 |
+
|
| 894 |
+
# Convert color from Hex to BGR
|
| 895 |
+
text_color_bgr = tuple(int(text_color[i:i+2], 16) for i in (5, 3, 1))
|
| 896 |
+
|
| 897 |
+
# Add Text to Canvas
|
| 898 |
+
cv2.putText(canvas, text, text_position, font, font_size, text_color_bgr, text_thickness, lineType=cv2.LINE_AA)
|
| 899 |
+
|
| 900 |
+
# Display the updated canvas
|
| 901 |
+
st.image(canvas, channels="BGR", use_column_width=True)
|
| 902 |
|
| 903 |
|
| 904 |
if 'page' not in st.session_state:
|