File size: 2,698 Bytes
f0f1e02
 
e1cabe7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f0f1e02
 
 
 
5c2660e
 
e1cabe7
5c2660e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e1cabe7
 
 
 
 
 
 
 
 
 
 
 
f0f1e02
 
 
 
 
e1cabe7
5c2660e
f0f1e02
e1cabe7
 
 
f0f1e02
 
e1cabe7
 
 
 
 
 
 
 
f0f1e02
5c2660e
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
import streamlit as st

def convert_temperature(value, unit):
    if unit == "Celsius":
        fahrenheit = (value * 9/5) + 32
        kelvin = value + 273.15
        return fahrenheit, kelvin
    elif unit == "Fahrenheit":
        celsius = (value - 32) * 5/9
        kelvin = celsius + 273.15
        return celsius, kelvin
    elif unit == "Kelvin":
        celsius = value - 273.15
        fahrenheit = (celsius * 9/5) + 32
        return celsius, fahrenheit

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

st.markdown(
    """
    <style>
        html, body, [class*="st-"] {
            transition: all 0.3s ease-in-out;
        }
        @media (prefers-color-scheme: light) {
            body {
                background: linear-gradient(to right, #E3F2FD, #BBDEFB);
                color: #333;
            }
            .stApp {
                background-color: rgba(255, 255, 255, 0.9);
                padding: 20px;
                border-radius: 10px;
                box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
            }
        }
        @media (prefers-color-scheme: dark) {
            body {
                background: linear-gradient(to right, #1E1E1E, #424242);
                color: white;
            }
            .stApp {
                background-color: rgba(0, 0, 0, 0.8);
                padding: 20px;
                border-radius: 10px;
                box-shadow: 0px 0px 10px rgba(255, 255, 255, 0.2);
            }
        }
        .stButton>button {
            background-color: #FF5733;
            color: white;
            font-size: 16px;
            border-radius: 8px;
        }
        .stNumberInput input {
            background-color: white;
            color: black;
            border-radius: 5px;
        }
    </style>
    """,
    unsafe_allow_html=True
)

st.title("🌡 Temperature Converter")
st.markdown("Convert temperatures between Celsius, Fahrenheit, and Kelvin effortlessly. Enter a value, choose a unit, and get instant results!")

# Input Section
unit = st.selectbox("Select the unit of the input temperature:", ["Celsius", "Fahrenheit", "Kelvin"])
value = st.number_input("Enter the temperature value:", format="%.2f")

if st.button("Convert"):
    result1, result2 = convert_temperature(value, unit)
    
    if unit == "Celsius":
        st.success(f"{value}°C = {result1:.2f}°F = {result2:.2f}K")
    elif unit == "Fahrenheit":
        st.success(f"{value}°F = {result1:.2f}°C = {result2:.2f}K")
    elif unit == "Kelvin":
        st.success(f"{value}K = {result1:.2f}°C = {result2:.2f}°F")

st.markdown("**Made with ❤️ using Streamlit**")