Blessin commited on
Commit
077cc09
·
verified ·
1 Parent(s): d3940a6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -8
app.py CHANGED
@@ -8,15 +8,17 @@ import matplotlib.pyplot as plt
8
  # Streamlit UI
9
  st.title('Celsius to Fahrenheit Conversion with TensorFlow')
10
 
11
- # Define the model with initial weights set
12
  model = tf.keras.Sequential([
13
- tf.keras.layers.Dense(units=1, input_shape=[1], kernel_initializer='zeros', bias_initializer='zeros')
14
  ])
15
 
16
- # Set a smaller learning rate for the optimizer
17
- optimizer = tf.keras.optimizers.Adam(learning_rate=0.001)
 
18
 
19
- # Compile the model with an optimizer and loss function
 
20
  model.compile(optimizer=optimizer, loss='mse')
21
 
22
  # Training data (Celsius to Fahrenheit)
@@ -26,12 +28,10 @@ fahrenheit = np.array([-40, 14, 32, 46.4, 59, 71.6, 100.4], dtype=float)
26
  # User input for the Celsius value to predict Fahrenheit
27
  input_celsius = st.number_input('Enter Celsius value:', value=0.0, format="%.1f")
28
 
29
- # Train the model with a fixed number of epochs
30
- epochs = 100
31
-
32
  # Button to train the model and make prediction
33
  if st.button('Train Model and Predict Fahrenheit'):
34
  with st.spinner('Training...'):
 
35
  model.fit(celsius, fahrenheit, epochs=epochs)
36
  st.success('Training completed!')
37
 
 
8
  # Streamlit UI
9
  st.title('Celsius to Fahrenheit Conversion with TensorFlow')
10
 
11
+ # Define the model
12
  model = tf.keras.Sequential([
13
+ tf.keras.layers.Dense(units=1, input_shape=[1])
14
  ])
15
 
16
+ # Sidebar for hyperparameter tuning
17
+ learning_rate = st.sidebar.slider('Learning Rate', 0.001, 0.1, 0.01)
18
+ epochs = st.sidebar.slider('Epochs', 100, 1000, 500)
19
 
20
+ # Compile the model with selected optimizer and loss function
21
+ optimizer = tf.keras.optimizers.SGD(learning_rate=learning_rate)
22
  model.compile(optimizer=optimizer, loss='mse')
23
 
24
  # Training data (Celsius to Fahrenheit)
 
28
  # User input for the Celsius value to predict Fahrenheit
29
  input_celsius = st.number_input('Enter Celsius value:', value=0.0, format="%.1f")
30
 
 
 
 
31
  # Button to train the model and make prediction
32
  if st.button('Train Model and Predict Fahrenheit'):
33
  with st.spinner('Training...'):
34
+ # Fit the model with the user-defined hyperparameters
35
  model.fit(celsius, fahrenheit, epochs=epochs)
36
  st.success('Training completed!')
37