File size: 3,261 Bytes
65c9117
aea6065
65c9117
aea6065
 
65c9117
aea6065
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65c9117
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
aea6065
 
 
65c9117
aea6065
 
 
65c9117
aea6065
 
65c9117
aea6065
 
 
 
 
 
 
 
 
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
import streamlit as st
import requests

# Title of the App with a background image and better UI
st.set_page_config(page_title="Temperature Converter", page_icon="🌡️", layout="wide")

# Custom CSS for improved UI
st.markdown("""
    <style>
        .main {
            background-color: #F0F8FF;
        }
        .title {
            color: #0044cc;
            font-size: 40px;
            font-weight: bold;
            text-align: center;
        }
        .input-field {
            background-color: #ffffff;
            border: 2px solid #0044cc;
            border-radius: 8px;
            padding: 10px;
            font-size: 18px;
        }
        .convert-btn {
            background-color: #0044cc;
            color: white;
            font-size: 18px;
            padding: 10px 20px;
            border-radius: 5px;
        }
        .result-text {
            font-size: 22px;
            font-weight: bold;
            color: #2e8b57;
            text-align: center;
        }
        .footer {
            text-align: center;
            margin-top: 20px;
            color: #888888;
            font-size: 14px;
        }
    </style>
""", unsafe_allow_html=True)

# Display the title with temperature-themed animation
st.markdown('<div class="title">Temperature Converter App 🌡️</div>', unsafe_allow_html=True)

# 3D Animated Visualization - Embedding a rotating globe with temperature visuals
st.markdown("""
    <h3 style="text-align:center;">Temperature across the globe 🌍</h3>
    <iframe src="https://www.meteomatics.com/en/weather-forecast-3d-globe/" width="100%" height="500px"></iframe>
""", unsafe_allow_html=True)

# Conversion Logic for the temperature
def convert_temperature(value, from_unit, to_unit):
    if from_unit == 'Celsius':
        if to_unit == 'Fahrenheit':
            return (value * 9/5) + 32
        elif to_unit == 'Kelvin':
            return value + 273.15
    elif from_unit == 'Fahrenheit':
        if to_unit == 'Celsius':
            return (value - 32) * 5/9
        elif to_unit == 'Kelvin':
            return (value - 32) * 5/9 + 273.15
    elif from_unit == 'Kelvin':
        if to_unit == 'Celsius':
            return value - 273.15
        elif to_unit == 'Fahrenheit':
            return (value - 273.15) * 9/5 + 32
    return value

# Temperature input fields
st.header("Enter the values for conversion")
value = st.number_input("Enter temperature value:", value=0.0, step=0.1, format="%.1f", className="input-field")

# Selectboxes for units
from_unit = st.selectbox("Select the unit to convert from", ['Celsius', 'Fahrenheit', 'Kelvin'], key="from_unit")
to_unit = st.selectbox("Select the unit to convert to", ['Celsius', 'Fahrenheit', 'Kelvin'], key="to_unit")

# Submit button to perform conversion
if st.button("Convert", key="convert_btn", help="Click to convert the temperature", use_container_width=True):
    result = convert_temperature(value, from_unit, to_unit)
    st.markdown(f'<div class="result-text">{value} {from_unit} is equal to {result} {to_unit}</div>', unsafe_allow_html=True)

# Footer - A simple message
st.markdown("""
    <div class="footer">
        Made with ❤️ by [Your Name]. Temperature converter app.
    </div>
""", unsafe_allow_html=True)