TempConv / app.py
F24EE's picture
Create app.py
044d429 verified
import streamlit as st
# Function to convert Celsius to other units
def convert_temperature(celsius):
fahrenheit = (celsius * 9/5) + 32
kelvin = celsius + 273.15
return fahrenheit, kelvin
# Streamlit UI setup
st.set_page_config(page_title="Temperature Converter", layout="wide")
# Title and Description
st.title("Interactive Temperature Converter")
st.markdown("### Convert temperatures between Celsius, Fahrenheit, and Kelvin")
# Create columns for layout
col1, col2, col3 = st.columns(3)
# Column 1: User input for Celsius temperature
with col1:
celsius = st.number_input("Enter temperature in Celsius:", value=0, step=1)
# Column 2: Converted temperatures
with col2:
if celsius is not None:
fahrenheit, kelvin = convert_temperature(celsius)
st.subheader("Converted Values:")
st.write(f"Fahrenheit: {fahrenheit:.2f} °F")
st.write(f"Kelvin: {kelvin:.2f} K")
# Column 3: User input for Fahrenheit temperature (Optional)
with col3:
fahrenheit_input = st.number_input("Enter temperature in Fahrenheit:", value=32, step=1)
if fahrenheit_input is not None:
celsius_from_fahrenheit = (fahrenheit_input - 32) * 5/9
kelvin_from_fahrenheit = (fahrenheit_input - 32) * 5/9 + 273.15
st.subheader("Converted from Fahrenheit:")
st.write(f"Celsius: {celsius_from_fahrenheit:.2f} °C")
st.write(f"Kelvin: {kelvin_from_fahrenheit:.2f} K")
# Footer
st.markdown("---")
st.markdown("Created by [Your Name].")