Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -19,10 +19,15 @@ def fahrenheit_to_kelvin(fahrenheit):
|
|
| 19 |
def kelvin_to_fahrenheit(kelvin):
|
| 20 |
return celsius_to_fahrenheit(kelvin_to_celsius(kelvin))
|
| 21 |
|
| 22 |
-
#
|
| 23 |
-
st.title("
|
|
|
|
| 24 |
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
"Choose Conversion Type:",
|
| 27 |
(
|
| 28 |
"Celsius to Fahrenheit",
|
|
@@ -34,39 +39,55 @@ conversion_type = st.selectbox(
|
|
| 34 |
)
|
| 35 |
)
|
| 36 |
|
| 37 |
-
#
|
| 38 |
-
|
| 39 |
-
celsius = st.number_input("Enter temperature in Celsius:", min_value=-273.15, step=0.1)
|
| 40 |
-
if st.button("Convert"):
|
| 41 |
-
fahrenheit = celsius_to_fahrenheit(celsius)
|
| 42 |
-
st.success(f"{celsius}°C is equal to {fahrenheit:.2f}°F")
|
| 43 |
-
|
| 44 |
-
elif conversion_type == "Fahrenheit to Celsius":
|
| 45 |
-
fahrenheit = st.number_input("Enter temperature in Fahrenheit:", min_value=-459.67, step=0.1)
|
| 46 |
-
if st.button("Convert"):
|
| 47 |
-
celsius = fahrenheit_to_celsius(fahrenheit)
|
| 48 |
-
st.success(f"{fahrenheit}°F is equal to {celsius:.2f}°C")
|
| 49 |
-
|
| 50 |
-
elif conversion_type == "Celsius to Kelvin":
|
| 51 |
-
celsius = st.number_input("Enter temperature in Celsius:", min_value=-273.15, step=0.1)
|
| 52 |
-
if st.button("Convert"):
|
| 53 |
-
kelvin = celsius_to_kelvin(celsius)
|
| 54 |
-
st.success(f"{celsius}°C is equal to {kelvin:.2f} K")
|
| 55 |
-
|
| 56 |
-
elif conversion_type == "Kelvin to Celsius":
|
| 57 |
-
kelvin = st.number_input("Enter temperature in Kelvin:", min_value=0.0, step=0.1)
|
| 58 |
-
if st.button("Convert"):
|
| 59 |
-
celsius = kelvin_to_celsius(kelvin)
|
| 60 |
-
st.success(f"{kelvin} K is equal to {celsius:.2f}°C")
|
| 61 |
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
if
|
| 65 |
-
|
| 66 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
st.success(f"{kelvin} K is equal to {fahrenheit:.2f}°F")
|
|
|
|
| 19 |
def kelvin_to_fahrenheit(kelvin):
|
| 20 |
return celsius_to_fahrenheit(kelvin_to_celsius(kelvin))
|
| 21 |
|
| 22 |
+
# Sidebar for navigation
|
| 23 |
+
st.sidebar.title("Navigation")
|
| 24 |
+
st.sidebar.info("Choose the conversion type and enter the temperature value in the input box below.")
|
| 25 |
|
| 26 |
+
# Main title
|
| 27 |
+
st.title("🌡️ Temperature Conversion App")
|
| 28 |
+
|
| 29 |
+
# Conversion options in sidebar
|
| 30 |
+
conversion_type = st.sidebar.radio(
|
| 31 |
"Choose Conversion Type:",
|
| 32 |
(
|
| 33 |
"Celsius to Fahrenheit",
|
|
|
|
| 39 |
)
|
| 40 |
)
|
| 41 |
|
| 42 |
+
# Layout: Use two columns for input and output
|
| 43 |
+
col1, col2 = st.columns(2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
+
with col1:
|
| 46 |
+
st.header("Input")
|
| 47 |
+
if conversion_type == "Celsius to Fahrenheit":
|
| 48 |
+
celsius = st.number_input("Enter temperature in Celsius:", min_value=-273.15, step=0.1)
|
| 49 |
+
if st.button("Convert"):
|
| 50 |
+
fahrenheit = celsius_to_fahrenheit(celsius)
|
| 51 |
+
with col2:
|
| 52 |
+
st.header("Output")
|
| 53 |
+
st.success(f"{celsius}°C = {fahrenheit:.2f}°F")
|
| 54 |
+
elif conversion_type == "Fahrenheit to Celsius":
|
| 55 |
+
fahrenheit = st.number_input("Enter temperature in Fahrenheit:", min_value=-459.67, step=0.1)
|
| 56 |
+
if st.button("Convert"):
|
| 57 |
+
celsius = fahrenheit_to_celsius(fahrenheit)
|
| 58 |
+
with col2:
|
| 59 |
+
st.header("Output")
|
| 60 |
+
st.success(f"{fahrenheit}°F = {celsius:.2f}°C")
|
| 61 |
+
elif conversion_type == "Celsius to Kelvin":
|
| 62 |
+
celsius = st.number_input("Enter temperature in Celsius:", min_value=-273.15, step=0.1)
|
| 63 |
+
if st.button("Convert"):
|
| 64 |
+
kelvin = celsius_to_kelvin(celsius)
|
| 65 |
+
with col2:
|
| 66 |
+
st.header("Output")
|
| 67 |
+
st.success(f"{celsius}°C = {kelvin:.2f} K")
|
| 68 |
+
elif conversion_type == "Kelvin to Celsius":
|
| 69 |
+
kelvin = st.number_input("Enter temperature in Kelvin:", min_value=0.0, step=0.1)
|
| 70 |
+
if st.button("Convert"):
|
| 71 |
+
celsius = kelvin_to_celsius(kelvin)
|
| 72 |
+
with col2:
|
| 73 |
+
st.header("Output")
|
| 74 |
+
st.success(f"{kelvin} K = {celsius:.2f}°C")
|
| 75 |
+
elif conversion_type == "Fahrenheit to Kelvin":
|
| 76 |
+
fahrenheit = st.number_input("Enter temperature in Fahrenheit:", min_value=-459.67, step=0.1)
|
| 77 |
+
if st.button("Convert"):
|
| 78 |
+
kelvin = fahrenheit_to_kelvin(fahrenheit)
|
| 79 |
+
with col2:
|
| 80 |
+
st.header("Output")
|
| 81 |
+
st.success(f"{fahrenheit}°F = {kelvin:.2f} K")
|
| 82 |
+
elif conversion_type == "Kelvin to Fahrenheit":
|
| 83 |
+
kelvin = st.number_input("Enter temperature in Kelvin:", min_value=0.0, step=0.1)
|
| 84 |
+
if st.button("Convert"):
|
| 85 |
+
fahrenheit = kelvin_to_fahrenheit(kelvin)
|
| 86 |
+
with col2:
|
| 87 |
+
st.header("Output")
|
| 88 |
+
st.success(f"{kelvin} K = {fahrenheit:.2f}°F")
|
| 89 |
|
| 90 |
+
# Footer
|
| 91 |
+
st.sidebar.markdown("----")
|
| 92 |
+
st.sidebar.write("Developed by **Malik Shehram Khan**")
|
| 93 |
+
st.sidebar.markdown("🌐 Powered by [Streamlit](https://streamlit.io)")
|
|
|