shubham680 commited on
Commit
f043d6a
·
verified ·
1 Parent(s): b91e62f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -136
app.py CHANGED
@@ -1,139 +1,3 @@
1
- # import streamlit as st
2
- # import numpy as np
3
- # import sympy as sp
4
- # import plotly.graph_objs as go
5
-
6
- # st.set_page_config(page_title="Gradient Descent Visualizer", layout="wide")
7
-
8
-
9
- # # Custom CSS for styling
10
- # st.markdown("""
11
- # <style>
12
- # /* Page background */
13
- # .stApp {
14
- # background-color: #f9f9f9;
15
- # font-family: 'Segoe UI', sans-serif;
16
- # }
17
-
18
- # /* Title */
19
- # h1 {
20
- # text-align: center;
21
- # color: #2C3E50;
22
- # font-size: 38px !important;
23
- # font-weight: bold;
24
- # margin-bottom: 20px;
25
- # }
26
-
27
- # /* Input boxes */
28
- # .stTextInput > div > div > input {
29
- # border: 2px solid #3498DB;
30
- # border-radius: 8px;
31
- # padding: 8px;
32
- # }
33
-
34
- # /* Buttons */
35
- # div.stButton > button {
36
- # background-color: #3498DB;
37
- # color: white;
38
- # border-radius: 10px;
39
- # padding: 10px 24px;
40
- # font-size: 16px;
41
- # border: none;
42
- # transition: 0.3s;
43
- # }
44
- # div.stButton > button:hover {
45
- # background-color: #2980B9;
46
- # transform: scale(1.05);
47
- # }
48
-
49
- # /* Success / Error messages */
50
- # .stAlert {
51
- # border-radius: 8px;
52
- # }
53
-
54
- # /* Chart section */
55
- # .block-container {
56
- # padding-top: 2rem;
57
- # padding-bottom: 2rem;
58
- # }
59
- # </style>
60
- # """, unsafe_allow_html=True)
61
-
62
-
63
- # st.title("Gradient Descent Visualizer")
64
-
65
- # x = sp.Symbol("x")
66
- # # User input function, starting point, and learning rate
67
- # func_input = st.text_input("Enter Function", "x^2")
68
- # start_point = float(st.text_input("Starting Point", "2"))
69
- # learning_rate = float(st.text_input("Learning Rate", "0.01"))
70
-
71
- # if st.button("Set Up") or 'func' not in st.session_state or 'points' not in st.session_state:
72
- # try:
73
- # expr = func_input.replace("^", "**")
74
- # expr_final = sp.sympify(expr)
75
- # func = sp.lambdify(x, expr_final, "numpy")
76
- # grad = sp.diff(expr_final, x)
77
- # gradient_func = sp.lambdify(x, grad, "numpy")
78
-
79
- # st.session_state.func = func
80
- # st.session_state.gradient_func = gradient_func
81
- # st.session_state.points = [start_point]
82
- # st.session_state.step = 0
83
- # st.success("Function and Gradient Set Up Successfully!")
84
-
85
- # except Exception as e:
86
- # st.error(f"Error setting up function: {e}")
87
-
88
- # # Gradient Descent Iteration button
89
- # if 'func' in st.session_state and 'gradient_func' in st.session_state:
90
- # if st.button("Next Iteration"):
91
- # try:
92
- # # Get the current point and gradient value
93
- # x_old = float(st.session_state.points[-1])
94
- # grad_val = st.session_state.gradient_func(x_old)
95
- # x_new = x_old - learning_rate * grad_val
96
-
97
- # # Append the new point to the list of points
98
- # st.session_state.points.append(x_new)
99
- # st.session_state.step += 1
100
-
101
- # st.success(f"Iteration {st.session_state.step} Complete!")
102
-
103
- # except Exception as e:
104
- # st.error(f"Error in iteration: {e}")
105
-
106
- # # Creating the plot
107
- # if 'func' in st.session_state and len(st.session_state.points) > 0:
108
- # try:
109
- # # Create x-values for plotting the function
110
- # x_val = np.linspace(-10, 10, 500)
111
- # y_val = st.session_state.func(x_val)
112
-
113
- # iter_points = np.array(st.session_state.points)
114
- # iter_y = st.session_state.func(iter_points)
115
-
116
- # trace1 = go.Scatter(x=x_val, y=y_val, mode="lines", name="Function", line=dict(color="blue"))
117
- # trace2 = go.Scatter(x=iter_points, y=iter_y, mode="markers+lines", name="Gradient Descent Path", marker=dict(color="red"))
118
- # trace3 = go.Scatter(x=[iter_points[-1]], y=[iter_y[-1]], mode='markers+text',
119
- # marker=dict(color='green', size=15),
120
- # text=[f"{iter_points[-1]:.6f}"], textposition="top center",
121
- # name="Current Point")
122
-
123
- # layout = go.Layout(
124
- # title=f"Iteration {st.session_state.step}",
125
- # xaxis=dict(title="x - axis"),
126
- # yaxis=dict(title="y - axis")
127
- # )
128
-
129
- # fig = go.Figure(data=[trace1, trace2, trace3], layout=layout)
130
- # st.plotly_chart(fig, use_container_width=True)
131
- # st.success(f"Current Point = {iter_points[-1]}")
132
-
133
- # except Exception as e:
134
- # st.error(f"Plot error: {e}")
135
-
136
-
137
  import streamlit as st
138
  import numpy as np
139
  import sympy as sp
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
  import numpy as np
3
  import sympy as sp