Blessin commited on
Commit
d36cc65
·
verified ·
1 Parent(s): e30d640

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -18
app.py CHANGED
@@ -1,4 +1,4 @@
1
- # A simple Linear Regression example with TensorFlow
2
 
3
  import tensorflow as tf
4
  import numpy as np
@@ -6,7 +6,7 @@ import streamlit as st
6
  import matplotlib.pyplot as plt
7
 
8
  # Streamlit UI
9
- st.title('Simple Linear Regression with TensorFlow')
10
 
11
  # Define the model
12
  model = tf.keras.Sequential([
@@ -16,37 +16,37 @@ model = tf.keras.Sequential([
16
  # Compile the model with an optimizer and loss function
17
  model.compile(optimizer='sgd', loss='mse')
18
 
19
- # Training data
20
- xs = np.array([1.0, 2.0, 3.0, 4.0, 5.0], dtype=float)
21
- ys = np.array([1.5, 2.0, 2.5, 3.0, 3.5], dtype=float)
22
 
23
  # Display example input and output
24
- st.write("Example input (xs):", xs)
25
- st.write("Example output (ys):", ys)
26
 
27
- # User input for the new value to predict
28
- input_value = st.number_input('Enter your input value:', value=1.0, format="%.1f")
29
 
30
  # User input for epochs
31
  epochs = st.sidebar.slider("Number of epochs", 10, 500, 10)
32
 
33
  # Button to train the model and make prediction
34
- if st.button('Train Model and Predict'):
35
  with st.spinner('Training...'):
36
- model.fit(xs, ys, epochs=epochs)
37
  st.success('Training completed!')
38
 
39
  # Make prediction
40
- prediction = model.predict([input_value])
41
- st.write(f'For input {input_value}, the prediction is {prediction[0][0]}')
42
 
43
  # Predictions for visualization
44
- predictions = model.predict(xs)
45
 
46
  # Plotting
47
- plt.scatter(xs, ys, label='Actual')
48
- plt.plot(xs, predictions, color='red', label='Predicted')
49
- plt.xlabel('Input Feature')
50
- plt.ylabel('Output Value')
51
  plt.legend()
52
  st.pyplot(plt)
 
1
+ # A simple Linear Regression example for Celsius to Fahrenheit conversion with TensorFlow
2
 
3
  import tensorflow as tf
4
  import numpy as np
 
6
  import matplotlib.pyplot as plt
7
 
8
  # Streamlit UI
9
+ st.title('Celsius to Fahrenheit Conversion with TensorFlow')
10
 
11
  # Define the model
12
  model = tf.keras.Sequential([
 
16
  # Compile the model with an optimizer and loss function
17
  model.compile(optimizer='sgd', loss='mse')
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
 
30
  # User input for epochs
31
  epochs = st.sidebar.slider("Number of epochs", 10, 500, 10)
32
 
33
  # Button to train the model and make prediction
34
+ if st.button('Train Model and Predict Fahrenheit'):
35
  with st.spinner('Training...'):
36
+ model.fit(celsius, fahrenheit, epochs=epochs)
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[0][0]:.1f}°F')
42
 
43
  # Predictions for visualization
44
+ predictions = model.predict(celsius)
45
 
46
  # Plotting
47
+ plt.scatter(celsius, fahrenheit, label='Actual Conversion')
48
+ plt.plot(celsius, predictions, color='red', label='Predicted Conversion')
49
+ plt.xlabel('Celsius')
50
+ plt.ylabel('Fahrenheit')
51
  plt.legend()
52
  st.pyplot(plt)