import streamlit as st # Custom CSS for the UI st.markdown(""" """, unsafe_allow_html=True) # Function to convert temperatures def convert_temperature(value, from_unit, to_unit): if from_unit == to_unit: return value # Convert to Celsius if from_unit == "Fahrenheit": value = (value - 32) * 5 / 9 elif from_unit == "Kelvin": value = value - 273.15 # Convert from Celsius to target unit if to_unit == "Fahrenheit": return value * 9 / 5 + 32 elif to_unit == "Kelvin": return value + 273.15 else: return value # Streamlit UI st.title("🌡️ Temperature Converter") st.write("Convert temperatures between Celsius, Fahrenheit, and Kelvin with ease.") # Input temperature temp_value = st.number_input("Enter the temperature:", value=0.0, step=0.1, format="%.2f") # Units selection units = ["Celsius", "Fahrenheit", "Kelvin"] from_unit = st.selectbox("From Unit:", units) to_unit = st.selectbox("To Unit:", units) # Convert button if st.button("Convert"): converted_temp = convert_temperature(temp_value, from_unit, to_unit) st.success(f"The converted temperature is: **{converted_temp:.2f} {to_unit}**")