Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
|
| 3 |
+
# Title and Description
|
| 4 |
+
st.title("🌡️ Temperature Converter")
|
| 5 |
+
st.write("""
|
| 6 |
+
This app converts temperatures between Celsius, Fahrenheit, and Kelvin.
|
| 7 |
+
Enter a value and select the conversion type to get started.
|
| 8 |
+
""")
|
| 9 |
+
|
| 10 |
+
# Input Section
|
| 11 |
+
temperature = st.number_input("Enter the temperature value:", value=0.0)
|
| 12 |
+
conversion_type = st.selectbox(
|
| 13 |
+
"Choose the conversion type:",
|
| 14 |
+
["Celsius to Fahrenheit", "Celsius to Kelvin",
|
| 15 |
+
"Fahrenheit to Celsius", "Fahrenheit to Kelvin",
|
| 16 |
+
"Kelvin to Celsius", "Kelvin to Fahrenheit"]
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
# Conversion Logic
|
| 20 |
+
def convert_temperature(value, conversion):
|
| 21 |
+
if conversion == "Celsius to Fahrenheit":
|
| 22 |
+
return (value * 9/5) + 32
|
| 23 |
+
elif conversion == "Celsius to Kelvin":
|
| 24 |
+
return value + 273.15
|
| 25 |
+
elif conversion == "Fahrenheit to Celsius":
|
| 26 |
+
return (value - 32) * 5/9
|
| 27 |
+
elif conversion == "Fahrenheit to Kelvin":
|
| 28 |
+
return ((value - 32) * 5/9) + 273.15
|
| 29 |
+
elif conversion == "Kelvin to Celsius":
|
| 30 |
+
return value - 273.15
|
| 31 |
+
elif conversion == "Kelvin to Fahrenheit":
|
| 32 |
+
return ((value - 273.15) * 9/5) + 32
|
| 33 |
+
else:
|
| 34 |
+
return None
|
| 35 |
+
|
| 36 |
+
# Perform Conversion
|
| 37 |
+
result = convert_temperature(temperature, conversion_type)
|
| 38 |
+
|
| 39 |
+
# Display Result
|
| 40 |
+
if result is not None:
|
| 41 |
+
st.subheader(f"Converted Temperature: {result:.2f}")
|
| 42 |
+
else:
|
| 43 |
+
st.error("Invalid conversion type selected.")
|
| 44 |
+
|
| 45 |
+
# Footer
|
| 46 |
+
st.write("---")
|
| 47 |
+
st.markdown("Created with ❤️ using [Streamlit](https://streamlit.io/).")
|