Files changed (1) hide show
  1. app.py +21 -34
app.py CHANGED
@@ -3,19 +3,18 @@ import numpy as np
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,16 +23,17 @@ st.markdown(
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):
@@ -75,8 +75,8 @@ if "current_index" not in st.session_state:
75
  if "learning_rate" not in st.session_state:
76
  st.session_state.learning_rate = 0.1
77
 
78
- # Create two-column grid layout
79
- left_col, right_col = st.columns([1, 2])
80
 
81
  # Left side content
82
  with left_col:
@@ -152,8 +152,8 @@ with right_col:
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,8 +162,8 @@ with right_col:
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,29 +173,16 @@ with right_col:
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)
 
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
  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
+ .block-container {
33
+ padding: 0;
34
+ }
35
  </style>
36
+ """, unsafe_allow_html=True)
 
 
37
 
38
  # Safe function evaluation
39
  def evaluate_function(expression, x_value):
 
75
  if "learning_rate" not in st.session_state:
76
  st.session_state.learning_rate = 0.1
77
 
78
+ # Create a two-column layout with equal widths
79
+ left_col, right_col = st.columns(2)
80
 
81
  # Left side content
82
  with left_col:
 
152
  x=x_range,
153
  y=y_range,
154
  mode='lines',
155
+ name='Function',
156
+ line=dict(color='blue') # Blue color for curve
157
  ))
158
 
159
  # Add current point
 
162
  x=[x_current],
163
  y=[y_current],
164
  mode='markers',
165
+ name='Current Point',
166
+ marker=dict(size=12, color='red') # Red for current point
167
  ))
168
 
169
  # Add tangent line
 
173
  y=tangent_y,
174
  mode='lines',
175
  name='Tangent Line',
176
+ line=dict(dash='dash', color='yellow') # Yellow dashed line for tangent
177
  ))
178
 
179
  # Layout adjustments
180
  fig.update_layout(
181
  title="Gradient Descent Progress 🌟",
182
+ xaxis_title="x",
183
+ yaxis_title="f(x)",
184
  template="plotly_dark",
185
+ height=600
 
 
 
 
 
 
 
 
 
 
 
 
 
186
  )
187
 
188
  st.plotly_chart(fig, use_container_width=True)