File size: 1,301 Bytes
7019f2f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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
)