Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
|
| 3 |
+
# Page configuration
|
| 4 |
+
st.set_page_config(page_title="Temperature Converter", page_icon="🌡️", layout="centered")
|
| 5 |
+
|
| 6 |
+
# Styling
|
| 7 |
+
st.markdown(
|
| 8 |
+
"""
|
| 9 |
+
<style>
|
| 10 |
+
body {
|
| 11 |
+
background-color: #f4f4f4;
|
| 12 |
+
}
|
| 13 |
+
.stApp {
|
| 14 |
+
background: #ffffff;
|
| 15 |
+
padding: 2rem;
|
| 16 |
+
border-radius: 10px;
|
| 17 |
+
box-shadow: 0px 0px 20px rgba(0, 0, 0, 0.1);
|
| 18 |
+
text-align: center;
|
| 19 |
+
}
|
| 20 |
+
</style>
|
| 21 |
+
""",
|
| 22 |
+
unsafe_allow_html=True
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
# Title
|
| 26 |
+
st.title("🌡️ Temperature Converter")
|
| 27 |
+
|
| 28 |
+
# Temperature conversion function
|
| 29 |
+
def convert_temperature(value, from_unit, to_unit):
|
| 30 |
+
if from_unit == to_unit:
|
| 31 |
+
return value
|
| 32 |
+
elif from_unit == "Celsius":
|
| 33 |
+
return value * 9/5 + 32 if to_unit == "Fahrenheit" else value + 273.15
|
| 34 |
+
elif from_unit == "Fahrenheit":
|
| 35 |
+
return (value - 32) * 5/9 if to_unit == "Celsius" else (value - 32) * 5/9 + 273.15
|
| 36 |
+
elif from_unit == "Kelvin":
|
| 37 |
+
return value - 273.15 if to_unit == "Celsius" else (value - 273.15) * 9/5 + 32
|
| 38 |
+
|
| 39 |
+
# User input
|
| 40 |
+
temperature = st.number_input("Enter Temperature:", value=0.0, format="%.2f")
|
| 41 |
+
|
| 42 |
+
# Unit selection
|
| 43 |
+
from_unit = st.selectbox("Convert from:", ["Celsius", "Fahrenheit", "Kelvin"])
|
| 44 |
+
to_unit = st.selectbox("Convert to:", ["Celsius", "Fahrenheit", "Kelvin"])
|
| 45 |
+
|
| 46 |
+
# Convert button
|
| 47 |
+
if st.button("Convert"):
|
| 48 |
+
result = convert_temperature(temperature, from_unit, to_unit)
|
| 49 |
+
st.success(f"Converted Temperature: {result:.2f} {to_unit}")
|
| 50 |
+
|
| 51 |
+
# Footer
|
| 52 |
+
st.markdown("<small>Created with ❤️ using Streamlit</small>", unsafe_allow_html=True)
|