Hem345 commited on
Commit
059da41
·
verified ·
1 Parent(s): cdf06d5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -9
app.py CHANGED
@@ -18,7 +18,6 @@ def perform_linear_regression(X, Y):
18
 
19
  # Streamlit interface
20
  st.title("Linear Regression App")
21
-
22
  st.subheader("Input vectors X and Y")
23
 
24
  # Create two columns
@@ -26,22 +25,27 @@ col1, col2 = st.columns(2)
26
 
27
  # Input fields for vectors X and Y in the first column
28
  with col1:
29
- st.write("Enter values for X and Y:")
 
30
 
31
- x_values = [st.number_input(f"X[{i}]", value=0.0, key=f'x{i}') for i in range(3)]
32
- y_values = [st.number_input(f"Y[{i}]", value=0.0, key=f'y{i}') for i in range(3)]
 
 
 
 
 
33
 
34
- # Check if both vectors are filled
35
  if len(x_values) == 3 and len(y_values) == 3:
36
  slope, intercept = perform_linear_regression(x_values, y_values)
37
 
38
  slope = round(slope, 2)
39
  intercept = round(intercept, 2)
40
-
41
- # Display the slope and intercept at the top of the window
42
  st.write(f"Slope: {slope}")
43
  st.write(f"Intercept: {intercept}")
44
-
45
  # Display graph in the second column
46
  with col2:
47
  plt.figure(figsize=(8, 6))
@@ -58,4 +62,4 @@ if len(x_values) == 3 and len(y_values) == 3:
58
 
59
  st.pyplot(plt)
60
  else:
61
- st.write("Please provide 3 values for both vectors X and Y.")
 
18
 
19
  # Streamlit interface
20
  st.title("Linear Regression App")
 
21
  st.subheader("Input vectors X and Y")
22
 
23
  # Create two columns
 
25
 
26
  # Input fields for vectors X and Y in the first column
27
  with col1:
28
+ x_input = st.text_input("X values (comma-separated)", "0.0, 0.0, 0.0")
29
+ y_input = st.text_input("Y values (comma-separated)", "0.0, 0.0, 0.0")
30
 
31
+ # Parse the input strings into lists of floats
32
+ try:
33
+ x_values = [float(val.strip()) for val in x_input.split(",")]
34
+ y_values = [float(val.strip()) for val in y_input.split(",")]
35
+ except ValueError:
36
+ st.write("Please provide valid numeric inputs.")
37
+ x_values, y_values = [], []
38
 
39
+ # Proceed only if both vectors are valid and have 3 elements each
40
  if len(x_values) == 3 and len(y_values) == 3:
41
  slope, intercept = perform_linear_regression(x_values, y_values)
42
 
43
  slope = round(slope, 2)
44
  intercept = round(intercept, 2)
45
+
 
46
  st.write(f"Slope: {slope}")
47
  st.write(f"Intercept: {intercept}")
48
+
49
  # Display graph in the second column
50
  with col2:
51
  plt.figure(figsize=(8, 6))
 
62
 
63
  st.pyplot(plt)
64
  else:
65
+ st.write("Please provide valid inputs with 3 values each.")