Spaces:
Sleeping
Sleeping
import streamlit as st | |
# Temperature Conversion Functions | |
def celsius_to_fahrenheit(celsius): | |
return (celsius * 9/5) + 32 | |
def celsius_to_kelvin(celsius): | |
return celsius + 273.15 | |
def fahrenheit_to_celsius(fahrenheit): | |
return (fahrenheit - 32) * 5/9 | |
def fahrenheit_to_kelvin(fahrenheit): | |
return (fahrenheit - 32) * 5/9 + 273.15 | |
def kelvin_to_celsius(kelvin): | |
return kelvin - 273.15 | |
def kelvin_to_fahrenheit(kelvin): | |
return (kelvin - 273.15) * 9/5 + 32 | |
# Streamlit App UI | |
st.set_page_config(page_title="Temperature Converter", layout="wide") | |
st.title("🌡️ Temperature Converter") | |
st.sidebar.title("Conversion Settings") | |
conversion_type = st.sidebar.selectbox( | |
"Choose conversion type", | |
["Celsius to Fahrenheit", "Celsius to Kelvin", | |
"Fahrenheit to Celsius", "Fahrenheit to Kelvin", | |
"Kelvin to Celsius", "Kelvin to Fahrenheit"] | |
) | |
input_value = st.sidebar.number_input("Enter the temperature value", value=0.0) | |
st.sidebar.markdown("---") | |
st.sidebar.markdown("Developed with ❤️ using Streamlit") | |
# Columns for Input and Result | |
col1, col2 = st.columns(2) | |
with col1: | |
st.header("Input Temperature") | |
st.write(f"**{input_value}**") | |
with col2: | |
st.header("Converted Temperature") | |
if conversion_type == "Celsius to Fahrenheit": | |
result = celsius_to_fahrenheit(input_value) | |
elif conversion_type == "Celsius to Kelvin": | |
result = celsius_to_kelvin(input_value) | |
elif conversion_type == "Fahrenheit to Celsius": | |
result = fahrenheit_to_celsius(input_value) | |
elif conversion_type == "Fahrenheit to Kelvin": | |
result = fahrenheit_to_kelvin(input_value) | |
elif conversion_type == "Kelvin to Celsius": | |
result = kelvin_to_celsius(input_value) | |
elif conversion_type == "Kelvin to Fahrenheit": | |
result = kelvin_to_fahrenheit(input_value) | |
st.write(f"**{result:.2f}**") | |