Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -13,17 +13,19 @@ model = tf.keras.Sequential([
|
|
13 |
tf.keras.layers.Dense(units=1, input_shape=[1])
|
14 |
])
|
15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
# Compile the model with an optimizer and loss function
|
17 |
-
model.compile(optimizer=
|
18 |
|
19 |
# Training data (Celsius to Fahrenheit)
|
20 |
celsius = np.array([-40, -10, 0, 8, 15, 22, 38], dtype=float) # Celsius
|
21 |
fahrenheit = np.array([-40, 14, 32, 46.4, 59, 71.6, 100.4], dtype=float) # Corresponding Fahrenheit
|
22 |
|
23 |
-
# Display example input and output
|
24 |
-
st.write("Example Celsius values (input):", celsius)
|
25 |
-
st.write("Corresponding Fahrenheit values (output):", fahrenheit)
|
26 |
-
|
27 |
# User input for the Celsius value to predict Fahrenheit
|
28 |
input_celsius = st.number_input('Enter Celsius value:', value=0.0, format="%.1f")
|
29 |
|
@@ -37,8 +39,8 @@ if st.button('Train Model and Predict Fahrenheit'):
|
|
37 |
st.success('Training completed!')
|
38 |
|
39 |
# Make prediction
|
40 |
-
predicted_fahrenheit = model.predict([input_celsius])
|
41 |
-
st.write(f'For input of {input_celsius}°C, the predicted Fahrenheit value is {predicted_fahrenheit
|
42 |
|
43 |
# Predictions for visualization
|
44 |
predictions = model.predict(celsius)
|
|
|
13 |
tf.keras.layers.Dense(units=1, input_shape=[1])
|
14 |
])
|
15 |
|
16 |
+
# Optimizer selection
|
17 |
+
optimizer = st.sidebar.selectbox(
|
18 |
+
"Select optimizer",
|
19 |
+
('sgd', 'adam', 'rmsprop')
|
20 |
+
)
|
21 |
+
|
22 |
# Compile the model with an optimizer and loss function
|
23 |
+
model.compile(optimizer=optimizer, loss='mse')
|
24 |
|
25 |
# Training data (Celsius to Fahrenheit)
|
26 |
celsius = np.array([-40, -10, 0, 8, 15, 22, 38], dtype=float) # Celsius
|
27 |
fahrenheit = np.array([-40, 14, 32, 46.4, 59, 71.6, 100.4], dtype=float) # Corresponding Fahrenheit
|
28 |
|
|
|
|
|
|
|
|
|
29 |
# User input for the Celsius value to predict Fahrenheit
|
30 |
input_celsius = st.number_input('Enter Celsius value:', value=0.0, format="%.1f")
|
31 |
|
|
|
39 |
st.success('Training completed!')
|
40 |
|
41 |
# Make prediction
|
42 |
+
predicted_fahrenheit = model.predict([input_celsius])[0][0]
|
43 |
+
st.write(f'For input of {input_celsius}°C, the predicted Fahrenheit value is {predicted_fahrenheit:.1f}°F')
|
44 |
|
45 |
# Predictions for visualization
|
46 |
predictions = model.predict(celsius)
|