UsmanGoraya's picture
Update app.py
7019f2f verified
import streamlit as st
# App configuration
st.set_page_config(
page_title="Temperature Converter",
page_icon="🌡️",
layout="centered",
)
# Title and description
st.title("🌡️ Temperature Converter")
st.markdown(
"""
Convert temperatures between **Fahrenheit** and **Celsius** using this simple and professional tool.
"""
)
# Temperature conversion functions
def fahrenheit_to_celsius(fahrenheit):
return (fahrenheit - 32) * 5 / 9
def celsius_to_fahrenheit(celsius):
return (celsius * 9 / 5) + 32
# Input section
conversion_type = st.selectbox("Choose conversion type:", ["Fahrenheit to Celsius", "Celsius to Fahrenheit"])
temperature = st.number_input("Enter temperature value:", format="%.2f")
# Conversion and output
if st.button("Convert"):
if conversion_type == "Fahrenheit to Celsius":
result = fahrenheit_to_celsius(temperature)
st.success(f"{temperature} °F is {result:.2f} °C")
else:
result = celsius_to_fahrenheit(temperature)
st.success(f"{temperature} °C is {result:.2f} °F")
# Footer
st.markdown(
"""
<hr style="margin-top: 2em;">
<div style='text-align: center; color: gray; font-size: 0.9em'>
Made with ❤️ using Streamlit
</div>
""",
unsafe_allow_html=True
)