Mpavan45 commited on
Commit
6acb70a
·
verified ·
1 Parent(s): aa96b75

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -19
app.py CHANGED
@@ -32,8 +32,8 @@ def reset_session_state():
32
  st.session_state.x_points = [st.session_state.initial_point]
33
  st.session_state.y_points = [evaluate_function(st.session_state.math_function, st.session_state.initial_point)]
34
 
35
- # Create two-column grid layout for the left side
36
- left_col, right_col = st.columns([2, 1]) # 2 for left, 1 for right grid proportion
37
 
38
  # Left side content (Function Input and Gradient Descent Parameters)
39
  with left_col:
@@ -51,6 +51,10 @@ with left_col:
51
  "Learning Rate", value=0.1, step=0.01, format="%.2f", key="learning_rate", on_change=reset_session_state
52
  )
53
  st.markdown("---")
 
 
 
 
54
 
55
  # Right side content (Gradient Descent Updates and Progress)
56
  with right_col:
@@ -71,22 +75,6 @@ with right_col:
71
  except Exception as e:
72
  st.error(f"Error: {str(e)}")
73
 
74
- # Gradient Descent Progress Section with Different Style
75
- st.subheader("Gradient Descent Progress")
76
- st.markdown(f"**Iteration:** {st.session_state.iter_count}")
77
- st.markdown(f"**Current x Value:** {st.session_state.x_current:.4f}")
78
- st.markdown(f"**Current Function Value (f(x)):** {st.session_state.y_points[-1]:.4f}")
79
- st.markdown("---")
80
-
81
- # Styling the updates section
82
- st.markdown(
83
- f'<div style="background-color:#f0f0f0; padding: 10px; border-radius: 5px;">'
84
- f'<strong>Iteration: </strong>{st.session_state.iter_count} <br>'
85
- f'<strong>Current x Value: </strong>{st.session_state.x_current:.4f} <br>'
86
- f'<strong>Current f(x): </strong>{st.session_state.y_points[-1]:.4f}</div>',
87
- unsafe_allow_html=True
88
- )
89
-
90
  # Generate plot data
91
  x_vals = np.linspace(-10, 10, 400)
92
  y_vals = [evaluate_function(function_input, x) for x in x_vals]
@@ -136,5 +124,5 @@ plot.update_layout(
136
  legend=dict(bgcolor="rgba(255,255,255,0.5)", bordercolor="gray", borderwidth=1),
137
  )
138
 
139
- # Display the plot in the left side
140
  st.plotly_chart(plot, use_container_width=True)
 
32
  st.session_state.x_points = [st.session_state.initial_point]
33
  st.session_state.y_points = [evaluate_function(st.session_state.math_function, st.session_state.initial_point)]
34
 
35
+ # Create two-column grid layout for the left side (more space for the right graph)
36
+ left_col, right_col = st.columns([1, 2]) # 1 for left, 2 for right grid proportion
37
 
38
  # Left side content (Function Input and Gradient Descent Parameters)
39
  with left_col:
 
51
  "Learning Rate", value=0.1, step=0.01, format="%.2f", key="learning_rate", on_change=reset_session_state
52
  )
53
  st.markdown("---")
54
+
55
+ # Reset Button
56
+ if st.button("🔄 Reset"):
57
+ reset_session_state()
58
 
59
  # Right side content (Gradient Descent Updates and Progress)
60
  with right_col:
 
75
  except Exception as e:
76
  st.error(f"Error: {str(e)}")
77
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
  # Generate plot data
79
  x_vals = np.linspace(-10, 10, 400)
80
  y_vals = [evaluate_function(function_input, x) for x in x_vals]
 
124
  legend=dict(bgcolor="rgba(255,255,255,0.5)", bordercolor="gray", borderwidth=1),
125
  )
126
 
127
+ # Display the plot in the right side (with more space now)
128
  st.plotly_chart(plot, use_container_width=True)