File size: 3,069 Bytes
fa98af0
 
503ebe7
fa98af0
 
 
 
 
 
503ebe7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c549026
 
 
 
 
 
 
 
 
 
 
 
fa98af0
c549026
 
 
 
503ebe7
 
 
 
 
 
 
 
 
fa98af0
c549026
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import streamlit as st

# Conversion functions
def celsius_to_fahrenheit(celsius):
    return (celsius * 9/5) + 32

def fahrenheit_to_celsius(fahrenheit):
    return (fahrenheit - 32) * 5/9

def celsius_to_kelvin(celsius):
    return celsius + 273.15

def kelvin_to_celsius(kelvin):
    return kelvin - 273.15

def fahrenheit_to_kelvin(fahrenheit):
    celsius = fahrenheit_to_celsius(fahrenheit)
    return celsius_to_kelvin(celsius)

def kelvin_to_fahrenheit(kelvin):
    celsius = kelvin_to_celsius(kelvin)
    return celsius_to_fahrenheit(celsius)

# Streamlit app
st.set_page_config(
    page_title="Temperature Converter",
    page_icon="🌡️",
    layout="centered"
)

# App title with icon
st.markdown(
    "<h1 style='text-align: center; color: #FF5733;'>🌡️ Temperature Conversion App</h1>",
    unsafe_allow_html=True
)
st.write("Convert temperatures between Celsius, Fahrenheit, and Kelvin with ease!")

# Sidebar for user input
st.sidebar.header("Conversion Options")
conversion_type = st.sidebar.radio(
    "Choose a conversion type:",
    (
        "Celsius to Fahrenheit",
        "Fahrenheit to Celsius",
        "Celsius to Kelvin",
        "Kelvin to Celsius",
        "Fahrenheit to Kelvin",
        "Kelvin to Fahrenheit"
    )
)

st.sidebar.markdown(
    "<hr style='border: 1px solid #FF5733;'>",
    unsafe_allow_html=True
)

temperature_input = st.sidebar.number_input(
    "Enter the temperature value:",
    format="%.2f"
)

# Add a button for conversion
if st.sidebar.button("Convert"):
    if conversion_type == "Celsius to Fahrenheit":
        converted_temp = celsius_to_fahrenheit(temperature_input)
        result = f"{temperature_input}°C is equal to {converted_temp:.2f}°F."
    elif conversion_type == "Fahrenheit to Celsius":
        converted_temp = fahrenheit_to_celsius(temperature_input)
        result = f"{temperature_input}°F is equal to {converted_temp:.2f}°C."
    elif conversion_type == "Celsius to Kelvin":
        converted_temp = celsius_to_kelvin(temperature_input)
        result = f"{temperature_input}°C is equal to {converted_temp:.2f}K."
    elif conversion_type == "Kelvin to Celsius":
        converted_temp = kelvin_to_celsius(temperature_input)
        result = f"{temperature_input}K is equal to {converted_temp:.2f}°C."
    elif conversion_type == "Fahrenheit to Kelvin":
        converted_temp = fahrenheit_to_kelvin(temperature_input)
        result = f"{temperature_input}°F is equal to {converted_temp:.2f}K."
    elif conversion_type == "Kelvin to Fahrenheit":
        converted_temp = kelvin_to_fahrenheit(temperature_input)
        result = f"{temperature_input}K is equal to {converted_temp:.2f}°F."

    # Display result with styled text
    st.markdown(
        f"<h3 style='text-align: center; color: #33A1FF;'>{result}</h3>",
        unsafe_allow_html=True
    )

# Footer
st.markdown(
    "<hr style='border: 1px solid #FF5733;'>",
    unsafe_allow_html=True
)
st.markdown(
    "<p style='text-align: center;'>Made with ❤️ using Streamlit</p>",
    unsafe_allow_html=True
)