Mpavan45 commited on
Commit
f6819c8
·
verified ·
1 Parent(s): 3510c4a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -6
app.py CHANGED
@@ -66,7 +66,7 @@ if "x" not in st.session_state:
66
  st.session_state.y_vals = [safe_eval(func_input, starting_point)]
67
 
68
  # Perform one iteration when the button is pressed
69
- if st.sidebar.button("🔄 Perform Iteration"):
70
  try:
71
  grad = derivative(func_input, st.session_state.x)
72
  st.session_state.x -= learning_rate * grad
@@ -76,6 +76,10 @@ if st.sidebar.button("🔄 Perform Iteration"):
76
  except Exception as e:
77
  st.sidebar.error(f"Error: {str(e)}")
78
 
 
 
 
 
79
  # Display gradient descent progress
80
  st.subheader("🧮 Gradient Descent Progress")
81
  st.write(f"*Iteration:* {st.session_state.iteration}")
@@ -90,12 +94,12 @@ y_range = [safe_eval(func_input, x) for x in x_range]
90
  fig = go.Figure()
91
 
92
  # Plot the function with a cool gradient color
93
- fig.add_trace(go.Scatter(x=x_range, y=y_range, mode="lines", line=dict(color="royalblue", width=3), name="Function"))
94
 
95
  # Plot gradient descent points with purple color
96
  fig.add_trace(go.Scatter(
97
  x=st.session_state.x_vals, y=st.session_state.y_vals,
98
- mode="markers", marker=dict(color="mediumvioletred", size=10, symbol="circle"), name="Gradient Descent Points"
99
  ))
100
 
101
  # Plot tangent line at current point with dotted line
@@ -108,7 +112,7 @@ tangent_y = tangent_line(func_input, current_x, tangent_x)
108
 
109
  fig.add_trace(go.Scatter(
110
  x=tangent_x, y=tangent_y, mode="lines",
111
- line=dict(color="orange", dash="dot", width=2), name="Tangent Line"
112
  ))
113
 
114
  # Customize the layout with a soft gradient background
@@ -117,8 +121,8 @@ fig.update_layout(
117
  xaxis=dict(title="x", range=[-2, 6], showgrid=False),
118
  yaxis=dict(title="f(x)", showgrid=False),
119
  template="plotly",
120
- plot_bgcolor="rgb(243, 243, 243)", # Soft background color
121
- paper_bgcolor="rgb(243, 243, 243)", # Soft background color
122
  font=dict(family="Arial, sans-serif", size=14, color="black"),
123
  legend=dict(orientation="h", yanchor="bottom", y=1.02, xanchor="right", x=1),
124
  )
 
66
  st.session_state.y_vals = [safe_eval(func_input, starting_point)]
67
 
68
  # Perform one iteration when the button is pressed
69
+ if st.sidebar.button("🔄 Run Descent Step"):
70
  try:
71
  grad = derivative(func_input, st.session_state.x)
72
  st.session_state.x -= learning_rate * grad
 
76
  except Exception as e:
77
  st.sidebar.error(f"Error: {str(e)}")
78
 
79
+ # Reset button
80
+ if st.sidebar.button("🔄 Reset"):
81
+ reset_state()
82
+
83
  # Display gradient descent progress
84
  st.subheader("🧮 Gradient Descent Progress")
85
  st.write(f"*Iteration:* {st.session_state.iteration}")
 
94
  fig = go.Figure()
95
 
96
  # Plot the function with a cool gradient color
97
+ fig.add_trace(go.Scatter(x=x_range, y=y_range, mode="lines", line=dict(color="mediumslateblue", width=3), name="Function"))
98
 
99
  # Plot gradient descent points with purple color
100
  fig.add_trace(go.Scatter(
101
  x=st.session_state.x_vals, y=st.session_state.y_vals,
102
+ mode="markers", marker=dict(color="crimson", size=10, symbol="circle"), name="Gradient Descent Points"
103
  ))
104
 
105
  # Plot tangent line at current point with dotted line
 
112
 
113
  fig.add_trace(go.Scatter(
114
  x=tangent_x, y=tangent_y, mode="lines",
115
+ line=dict(color="gold", dash="dot", width=2), name="Tangent Line"
116
  ))
117
 
118
  # Customize the layout with a soft gradient background
 
121
  xaxis=dict(title="x", range=[-2, 6], showgrid=False),
122
  yaxis=dict(title="f(x)", showgrid=False),
123
  template="plotly",
124
+ plot_bgcolor="rgb(250, 250, 250)", # Light background for a soft look
125
+ paper_bgcolor="rgb(250, 250, 250)", # Consistent soft background color
126
  font=dict(family="Arial, sans-serif", size=14, color="black"),
127
  legend=dict(orientation="h", yanchor="bottom", y=1.02, xanchor="right", x=1),
128
  )