Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| 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 # Same unit, no conversion | |
| def main(): | |
| st.title("Temperature Conversion App") | |
| st.sidebar.header("Input Temperature") | |
| temperature = st.sidebar.number_input("Enter the temperature value:", value=0.0) | |
| from_unit = st.sidebar.selectbox("From unit:", ["Celsius", "Fahrenheit", "Kelvin"]) | |
| to_unit = st.sidebar.selectbox("To unit:", ["Celsius", "Fahrenheit", "Kelvin"]) | |
| if st.sidebar.button("Convert"): | |
| result = convert_temperature(temperature, from_unit, to_unit) | |
| st.success(f"{temperature} {from_unit} = {result:.2f} {to_unit}") | |
| st.sidebar.write("Developed by [Sami ullah]") | |
| if __name__ == "__main__": | |
| main() | |