Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,26 +4,37 @@ import plotly.graph_objects as go
|
|
| 4 |
|
| 5 |
# Title of the app
|
| 6 |
st.set_page_config(page_title="Interactive Gradient Descent Visualizer", layout="wide")
|
| 7 |
-
st.markdown("<h1 style='text-align: center; color:
|
| 8 |
|
| 9 |
# Custom CSS for background and button color
|
| 10 |
st.markdown("""
|
| 11 |
<style>
|
| 12 |
body {
|
| 13 |
-
background-color:
|
| 14 |
-
color: white; /*
|
| 15 |
}
|
| 16 |
.stButton>button {
|
| 17 |
-
background
|
| 18 |
-
color:
|
| 19 |
-
border
|
|
|
|
| 20 |
padding: 10px 20px;
|
| 21 |
font-size: 16px;
|
| 22 |
font-weight: bold;
|
|
|
|
| 23 |
}
|
| 24 |
.stButton>button:hover {
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
}
|
| 28 |
</style>
|
| 29 |
""", unsafe_allow_html=True)
|
|
@@ -73,14 +84,14 @@ left_col, right_col = st.columns([1, 2]) # 1 for left, 2 for right grid proport
|
|
| 73 |
|
| 74 |
# Left side content (Function Input and Gradient Descent Parameters)
|
| 75 |
with left_col:
|
| 76 |
-
st.markdown("<h3 style='color:
|
| 77 |
function_input = st.text_input(
|
| 78 |
"Enter Function:`Ex:'x**2`,`np.sin(x)`",
|
| 79 |
"x**2 + x",
|
| 80 |
key="math_function",
|
| 81 |
on_change=reset_session_state
|
| 82 |
)
|
| 83 |
-
st.markdown("<h3 style='color:
|
| 84 |
initial_point = st.number_input(
|
| 85 |
"Initial Value of x",
|
| 86 |
value=4.0,
|
|
@@ -97,7 +108,7 @@ with left_col:
|
|
| 97 |
key="learning_rate"
|
| 98 |
) # Updates session state directly without reset
|
| 99 |
|
| 100 |
-
st.markdown("<h3 style='color:
|
| 101 |
|
| 102 |
if st.button("🔄 Run Descent Step", type="primary"):
|
| 103 |
try:
|
|
@@ -115,7 +126,7 @@ with left_col:
|
|
| 115 |
|
| 116 |
# Right side content (Visualization and Iteration Details)
|
| 117 |
with right_col:
|
| 118 |
-
st.markdown("<h3 style='color:
|
| 119 |
|
| 120 |
# Display iteration details using buttons
|
| 121 |
col1, col2, col3 = st.columns(3)
|
|
@@ -130,8 +141,8 @@ with right_col:
|
|
| 130 |
|
| 131 |
try:
|
| 132 |
selected_x, selected_y = st.session_state.history[st.session_state.current_index]
|
| 133 |
-
st.markdown(f"x Value:
|
| 134 |
-
st.markdown(f"f(x):
|
| 135 |
except IndexError:
|
| 136 |
st.warning("No iteration data available. Please run a descent step first.")
|
| 137 |
|
|
|
|
| 4 |
|
| 5 |
# Title of the app
|
| 6 |
st.set_page_config(page_title="Interactive Gradient Descent Visualizer", layout="wide")
|
| 7 |
+
st.markdown("<h1 style='text-align: center; color: #FFD700;'> 🌟 Gradient Descent Visualizer</h1>", unsafe_allow_html=True)
|
| 8 |
|
| 9 |
# Custom CSS for background and button color
|
| 10 |
st.markdown("""
|
| 11 |
<style>
|
| 12 |
body {
|
| 13 |
+
background-color: #121212; /* Dark gray background for modern look */
|
| 14 |
+
color: white; /* White text for contrast */
|
| 15 |
}
|
| 16 |
.stButton>button {
|
| 17 |
+
background: linear-gradient(45deg, #FF7F50, #FF4500); /* Coral to OrangeRed gradient */
|
| 18 |
+
color: white; /* White button text */
|
| 19 |
+
border: none;
|
| 20 |
+
border-radius: 8px;
|
| 21 |
padding: 10px 20px;
|
| 22 |
font-size: 16px;
|
| 23 |
font-weight: bold;
|
| 24 |
+
transition: transform 0.2s ease, box-shadow 0.3s ease, filter 0.3s ease; /* Smooth hover effects */
|
| 25 |
}
|
| 26 |
.stButton>button:hover {
|
| 27 |
+
transform: scale(1.1); /* Slight zoom effect on hover */
|
| 28 |
+
box-shadow: 0 0 20px 10px rgba(255, 69, 0, 0.8); /* Glowing shadow effect */
|
| 29 |
+
background: linear-gradient(45deg, #FF4500, #FF7F50); /* Reverse gradient */
|
| 30 |
+
filter: brightness(1.2); /* Slightly brightens the button */
|
| 31 |
+
}
|
| 32 |
+
h1, h2, h3 {
|
| 33 |
+
color: #00FFFF; /* Aqua for headings */
|
| 34 |
+
}
|
| 35 |
+
.custom-text {
|
| 36 |
+
color: #FFD700; /* Gold for highlighted text */
|
| 37 |
+
font-weight: bold;
|
| 38 |
}
|
| 39 |
</style>
|
| 40 |
""", unsafe_allow_html=True)
|
|
|
|
| 84 |
|
| 85 |
# Left side content (Function Input and Gradient Descent Parameters)
|
| 86 |
with left_col:
|
| 87 |
+
st.markdown("<h3 style='color: #7FFF00;'>Input Your Function</h3>", unsafe_allow_html=True)
|
| 88 |
function_input = st.text_input(
|
| 89 |
"Enter Function:`Ex:'x**2`,`np.sin(x)`",
|
| 90 |
"x**2 + x",
|
| 91 |
key="math_function",
|
| 92 |
on_change=reset_session_state
|
| 93 |
)
|
| 94 |
+
st.markdown("<h3 style='color: #FF69B4;'>Set Parameters</h3>", unsafe_allow_html=True)
|
| 95 |
initial_point = st.number_input(
|
| 96 |
"Initial Value of x",
|
| 97 |
value=4.0,
|
|
|
|
| 108 |
key="learning_rate"
|
| 109 |
) # Updates session state directly without reset
|
| 110 |
|
| 111 |
+
st.markdown("<h3 style='color: #1E90FF;'>Controls</h3>", unsafe_allow_html=True)
|
| 112 |
|
| 113 |
if st.button("🔄 Run Descent Step", type="primary"):
|
| 114 |
try:
|
|
|
|
| 126 |
|
| 127 |
# Right side content (Visualization and Iteration Details)
|
| 128 |
with right_col:
|
| 129 |
+
st.markdown("<h3 style='color: #FF6347;'>Gradient Descent Visualization</h3>", unsafe_allow_html=True)
|
| 130 |
|
| 131 |
# Display iteration details using buttons
|
| 132 |
col1, col2, col3 = st.columns(3)
|
|
|
|
| 141 |
|
| 142 |
try:
|
| 143 |
selected_x, selected_y = st.session_state.history[st.session_state.current_index]
|
| 144 |
+
st.markdown(f"x Value: <span style='color: #FFD700;'>{selected_x:.4f}</span>", unsafe_allow_html=True)
|
| 145 |
+
st.markdown(f"f(x): <span style='color: #FFD700;'>{selected_y:.4f}</span>", unsafe_allow_html=True)
|
| 146 |
except IndexError:
|
| 147 |
st.warning("No iteration data available. Please run a descent step first.")
|
| 148 |
|