Spaces:
Sleeping
Sleeping
Update app.py
#1
by
trohith89
- opened
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="
|
| 7 |
-
st.markdown("<h1 style='text-align: center; color: #
|
| 8 |
|
| 9 |
# Custom CSS for enhanced UI
|
| 10 |
-
st.markdown(
|
|
|
|
| 11 |
<style>
|
| 12 |
body {
|
| 13 |
-
background: linear-gradient(to right, #
|
| 14 |
-
color: #
|
| 15 |
}
|
| 16 |
.stButton>button {
|
| 17 |
-
background: linear-gradient(to right, #
|
| 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, #
|
| 27 |
}
|
| 28 |
.iteration-controls button {
|
| 29 |
width: 100%;
|
| 30 |
margin: 5px 0;
|
| 31 |
}
|
| 32 |
</style>
|
| 33 |
-
""",
|
|
|
|
|
|
|
| 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='#
|
| 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='
|
| 163 |
-
marker=dict(size=12, color='#
|
| 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='#
|
| 174 |
))
|
| 175 |
|
| 176 |
# Layout adjustments
|
| 177 |
fig.update_layout(
|
| 178 |
title="Gradient Descent Progress π",
|
| 179 |
-
xaxis_title="x",
|
| 180 |
-
yaxis_title="
|
| 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)
|