Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -22,12 +22,23 @@ def kelvin_to_fahrenheit(kelvin):
|
|
| 22 |
return celsius_to_fahrenheit(celsius)
|
| 23 |
|
| 24 |
# Streamlit app
|
| 25 |
-
st.
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
-
#
|
| 29 |
-
|
| 30 |
-
|
|
|
|
| 31 |
(
|
| 32 |
"Celsius to Fahrenheit",
|
| 33 |
"Fahrenheit to Celsius",
|
|
@@ -38,24 +49,49 @@ conversion_type = st.selectbox(
|
|
| 38 |
)
|
| 39 |
)
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
elif conversion_type == "Fahrenheit to
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
elif conversion_type == "
|
| 60 |
-
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
return celsius_to_fahrenheit(celsius)
|
| 23 |
|
| 24 |
# Streamlit app
|
| 25 |
+
st.set_page_config(
|
| 26 |
+
page_title="Temperature Converter",
|
| 27 |
+
page_icon="🌡️",
|
| 28 |
+
layout="centered"
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
# App title with icon
|
| 32 |
+
st.markdown(
|
| 33 |
+
"<h1 style='text-align: center; color: #FF5733;'>🌡️ Temperature Conversion App</h1>",
|
| 34 |
+
unsafe_allow_html=True
|
| 35 |
+
)
|
| 36 |
+
st.write("Convert temperatures between Celsius, Fahrenheit, and Kelvin with ease!")
|
| 37 |
|
| 38 |
+
# Sidebar for user input
|
| 39 |
+
st.sidebar.header("Conversion Options")
|
| 40 |
+
conversion_type = st.sidebar.radio(
|
| 41 |
+
"Choose a conversion type:",
|
| 42 |
(
|
| 43 |
"Celsius to Fahrenheit",
|
| 44 |
"Fahrenheit to Celsius",
|
|
|
|
| 49 |
)
|
| 50 |
)
|
| 51 |
|
| 52 |
+
st.sidebar.markdown(
|
| 53 |
+
"<hr style='border: 1px solid #FF5733;'>",
|
| 54 |
+
unsafe_allow_html=True
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
temperature_input = st.sidebar.number_input(
|
| 58 |
+
"Enter the temperature value:",
|
| 59 |
+
format="%.2f"
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
# Add a button for conversion
|
| 63 |
+
if st.sidebar.button("Convert"):
|
| 64 |
+
if conversion_type == "Celsius to Fahrenheit":
|
| 65 |
+
converted_temp = celsius_to_fahrenheit(temperature_input)
|
| 66 |
+
result = f"{temperature_input}°C is equal to {converted_temp:.2f}°F."
|
| 67 |
+
elif conversion_type == "Fahrenheit to Celsius":
|
| 68 |
+
converted_temp = fahrenheit_to_celsius(temperature_input)
|
| 69 |
+
result = f"{temperature_input}°F is equal to {converted_temp:.2f}°C."
|
| 70 |
+
elif conversion_type == "Celsius to Kelvin":
|
| 71 |
+
converted_temp = celsius_to_kelvin(temperature_input)
|
| 72 |
+
result = f"{temperature_input}°C is equal to {converted_temp:.2f}K."
|
| 73 |
+
elif conversion_type == "Kelvin to Celsius":
|
| 74 |
+
converted_temp = kelvin_to_celsius(temperature_input)
|
| 75 |
+
result = f"{temperature_input}K is equal to {converted_temp:.2f}°C."
|
| 76 |
+
elif conversion_type == "Fahrenheit to Kelvin":
|
| 77 |
+
converted_temp = fahrenheit_to_kelvin(temperature_input)
|
| 78 |
+
result = f"{temperature_input}°F is equal to {converted_temp:.2f}K."
|
| 79 |
+
elif conversion_type == "Kelvin to Fahrenheit":
|
| 80 |
+
converted_temp = kelvin_to_fahrenheit(temperature_input)
|
| 81 |
+
result = f"{temperature_input}K is equal to {converted_temp:.2f}°F."
|
| 82 |
+
|
| 83 |
+
# Display result with styled text
|
| 84 |
+
st.markdown(
|
| 85 |
+
f"<h3 style='text-align: center; color: #33A1FF;'>{result}</h3>",
|
| 86 |
+
unsafe_allow_html=True
|
| 87 |
+
)
|
| 88 |
+
|
| 89 |
+
# Footer
|
| 90 |
+
st.markdown(
|
| 91 |
+
"<hr style='border: 1px solid #FF5733;'>",
|
| 92 |
+
unsafe_allow_html=True
|
| 93 |
+
)
|
| 94 |
+
st.markdown(
|
| 95 |
+
"<p style='text-align: center;'>Made with ❤️ using Streamlit</p>",
|
| 96 |
+
unsafe_allow_html=True
|
| 97 |
+
)
|