Spaces:
Sleeping
Sleeping
File size: 1,342 Bytes
ebeb38c 1c48f9d ebeb38c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
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()
|