Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
# Function for temperature conversion
|
4 |
+
def convert_temperature(value, from_unit, to_unit):
|
5 |
+
if from_unit == "Celsius" and to_unit == "Fahrenheit":
|
6 |
+
return (value * 9/5) + 32
|
7 |
+
elif from_unit == "Fahrenheit" and to_unit == "Celsius":
|
8 |
+
return (value - 32) * 5/9
|
9 |
+
elif from_unit == "Celsius" and to_unit == "Kelvin":
|
10 |
+
return value + 273.15
|
11 |
+
elif from_unit == "Kelvin" and to_unit == "Celsius":
|
12 |
+
return value - 273.15
|
13 |
+
elif from_unit == "Fahrenheit" and to_unit == "Kelvin":
|
14 |
+
return (value - 32) * 5/9 + 273.15
|
15 |
+
elif from_unit == "Kelvin" and to_unit == "Fahrenheit":
|
16 |
+
return (value - 273.15) * 9/5 + 32
|
17 |
+
else:
|
18 |
+
return value
|
19 |
+
|
20 |
+
# Streamlit interface
|
21 |
+
st.title('Temperature Converter')
|
22 |
+
st.write('This app allows you to convert between Celsius, Fahrenheit, and Kelvin.')
|
23 |
+
|
24 |
+
# Input from the user
|
25 |
+
value = st.number_input("Enter the temperature value:", min_value=-273.15)
|
26 |
+
from_unit = st.selectbox("Select the unit to convert from:", ["Celsius", "Fahrenheit", "Kelvin"])
|
27 |
+
to_unit = st.selectbox("Select the unit to convert to:", ["Celsius", "Fahrenheit", "Kelvin"])
|
28 |
+
|
29 |
+
# Perform conversion
|
30 |
+
if st.button("Convert"):
|
31 |
+
if from_unit != to_unit:
|
32 |
+
result = convert_temperature(value, from_unit, to_unit)
|
33 |
+
st.write(f"The converted temperature is {result:.2f} {to_unit}.")
|
34 |
+
else:
|
35 |
+
st.write("Please select different units for conversion.")
|