Zeeshan24's picture
Update app.py
b786662 verified
import streamlit as st
# Function to convert temperature
def convert_temperature(value, from_unit, to_unit):
if from_unit == "Celsius" and to_unit == "Fahrenheit":
return (value * 9/5) + 32
elif from_unit == "Celsius" and to_unit == "Kelvin":
return value + 273.15
elif from_unit == "Fahrenheit" and to_unit == "Celsius":
return (value - 32) * 5/9
elif from_unit == "Fahrenheit" and to_unit == "Kelvin":
return ((value - 32) * 5/9) + 273.15
elif from_unit == "Kelvin" and to_unit == "Celsius":
return value - 273.15
elif from_unit == "Kelvin" and to_unit == "Fahrenheit":
return ((value - 273.15) * 9/5) + 32
else:
return value
# Streamlit app UI
st.set_page_config(page_title="Temperature Conversion App", page_icon="🌡️")
# Heading with a custom font and color
st.title("🌡️ **Temperature Conversion App**")
st.markdown("<h3 style='color:#ff6347;'>Convert temperature units with ease!</h3>", unsafe_allow_html=True)
# Create columns for input and output
col1, col2 = st.columns(2)
with col1:
# Input section with a colorful header
st.markdown("<h4 style='color:#20b2aa;'>Input Temperature</h4>", unsafe_allow_html=True)
temperature = st.number_input("Enter the temperature value:", value=0.0, step=0.1, format="%.1f")
from_unit = st.selectbox("Select from unit", ["Celsius", "Fahrenheit", "Kelvin"])
with col2:
# Output section with a colorful header
st.markdown("<h4 style='color:#20b2aa;'>Output Temperature</h4>", unsafe_allow_html=True)
to_unit = st.selectbox("Select to unit", ["Celsius", "Fahrenheit", "Kelvin"])
# Add a colorful button for conversion
convert_button = st.button("🔄 Convert", key="convert_button", help="Click to convert the temperature", use_container_width=True)
# Display the result
if convert_button:
if from_unit == to_unit:
st.warning(f"The temperature is already in **{to_unit}**.")
else:
converted_value = convert_temperature(temperature, from_unit, to_unit)
st.success(f"{temperature} **{from_unit}** is equal to **{converted_value:.2f} {to_unit}**.")
# Footer with some styling
st.markdown("<br><hr><p style='text-align:center; color:#a9a9a9;'>Made with ❤️ by [Your Name]</p>", unsafe_allow_html=True)