Files changed (1) hide show
  1. app.py +32 -16
app.py CHANGED
@@ -3,18 +3,19 @@ import numpy as np
3
  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: #00FA9A;'>✨ Gradient Descent Visualizer ✨</h1>", unsafe_allow_html=True)
8
 
9
  # Custom CSS for enhanced UI
10
- st.markdown("""
 
11
  <style>
12
  body {
13
- background: linear-gradient(to right, #141E30, #243B55);
14
- color: #E0FFFF;
15
  }
16
  .stButton>button {
17
- background: linear-gradient(to right, #00C6FF, #0072FF);
18
  color: white;
19
  border: none;
20
  border-radius: 10px;
@@ -23,14 +24,16 @@ st.markdown("""
23
  font-weight: bold;
24
  }
25
  .stButton>button:hover {
26
- background: linear-gradient(to right, #0072FF, #00C6FF);
27
  }
28
  .iteration-controls button {
29
  width: 100%;
30
  margin: 5px 0;
31
  }
32
  </style>
33
- """, unsafe_allow_html=True)
 
 
34
 
35
  # Safe function evaluation
36
  def evaluate_function(expression, x_value):
@@ -149,8 +152,8 @@ with right_col:
149
  x=x_range,
150
  y=y_range,
151
  mode='lines',
152
- name='Function',
153
- line=dict(color='#FFD700') # Golden color for curve
154
  ))
155
 
156
  # Add current point
@@ -159,8 +162,8 @@ with right_col:
159
  x=[x_current],
160
  y=[y_current],
161
  mode='markers',
162
- name='Current Point',
163
- marker=dict(size=12, color='#FF4500') # Red-orange for current point
164
  ))
165
 
166
  # Add tangent line
@@ -170,16 +173,29 @@ with right_col:
170
  y=tangent_y,
171
  mode='lines',
172
  name='Tangent Line',
173
- line=dict(dash='dash', color='#1E90FF') # Dodger blue for tangent line
174
  ))
175
 
176
  # Layout adjustments
177
  fig.update_layout(
178
  title="Gradient Descent Progress 🌟",
179
- xaxis_title="x",
180
- yaxis_title="f(x)",
181
  template="plotly_dark",
182
- height=600
 
 
 
 
 
 
 
 
 
 
 
 
 
183
  )
184
 
185
  st.plotly_chart(fig, use_container_width=True)
 
3
  import plotly.graph_objects as go
4
 
5
  # Title of the app
6
+ st.set_page_config(page_title="Gradient Descent Visualizer", layout="wide")
7
+ st.markdown("<h1 style='text-align: center; color: #4CAF50;'>🌟 Gradient Descent Visualizer 🌟</h1>", unsafe_allow_html=True)
8
 
9
  # Custom CSS for enhanced UI
10
+ st.markdown(
11
+ """
12
  <style>
13
  body {
14
+ background: linear-gradient(to right, #2C3E50, #4CA1AF);
15
+ color: #FFFFFF;
16
  }
17
  .stButton>button {
18
+ background: linear-gradient(to right, #1D2671, #C33764);
19
  color: white;
20
  border: none;
21
  border-radius: 10px;
 
24
  font-weight: bold;
25
  }
26
  .stButton>button:hover {
27
+ background: linear-gradient(to right, #C33764, #1D2671);
28
  }
29
  .iteration-controls button {
30
  width: 100%;
31
  margin: 5px 0;
32
  }
33
  </style>
34
+ """,
35
+ unsafe_allow_html=True
36
+ )
37
 
38
  # Safe function evaluation
39
  def evaluate_function(expression, x_value):
 
152
  x=x_range,
153
  y=y_range,
154
  mode='lines',
155
+ name='Function Curve',
156
+ line=dict(color='#1E90FF', width=3) # Blue color for curve
157
  ))
158
 
159
  # Add current point
 
162
  x=[x_current],
163
  y=[y_current],
164
  mode='markers',
165
+ name='Gradient Descent Point',
166
+ marker=dict(size=12, color='#FF0000') # Red for gradient descent points
167
  ))
168
 
169
  # Add tangent line
 
173
  y=tangent_y,
174
  mode='lines',
175
  name='Tangent Line',
176
+ line=dict(dash='dash', color='#FFD700', width=2) # Yellow for tangent line
177
  ))
178
 
179
  # Layout adjustments
180
  fig.update_layout(
181
  title="Gradient Descent Progress 🌟",
182
+ xaxis_title="x-axis",
183
+ yaxis_title="y-axis",
184
  template="plotly_dark",
185
+ height=600,
186
+ annotations=[
187
+ dict(
188
+ x=x_current,
189
+ y=y_current,
190
+ xref="x",
191
+ yref="y",
192
+ text=f"x: {x_current:.2f}, y: {y_current:.2f}",
193
+ showarrow=True,
194
+ arrowhead=3,
195
+ ax=20,
196
+ ay=-30
197
+ )
198
+ ]
199
  )
200
 
201
  st.plotly_chart(fig, use_container_width=True)