aaqibkhan039's picture
Update app.py
5c2660e verified
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**")