Spaces:
Sleeping
Sleeping
Kamran Zulfiqar
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,24 +1,42 @@
|
|
1 |
import streamlit as st
|
2 |
|
3 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
st.title("🌡️ Temperature Converter")
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
("
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
st.metric("Converted Temperature (°C)", f"{temp_c:.2f} °C")
|
21 |
-
|
22 |
-
# Optional clear button (refreshes app)
|
23 |
-
if st.button("🔄 Reset"):
|
24 |
-
st.experimental_rerun()
|
|
|
1 |
import streamlit as st
|
2 |
|
3 |
+
# Temperature conversion functions
|
4 |
+
def convert_temperature(value, from_unit, to_unit):
|
5 |
+
if from_unit == to_unit:
|
6 |
+
return value
|
7 |
+
|
8 |
+
# Convert input to Celsius
|
9 |
+
if from_unit == "Celsius":
|
10 |
+
celsius = value
|
11 |
+
elif from_unit == "Fahrenheit":
|
12 |
+
celsius = (value - 32) * 5/9
|
13 |
+
elif from_unit == "Kelvin":
|
14 |
+
celsius = value - 273.15
|
15 |
+
|
16 |
+
# Convert from Celsius to target
|
17 |
+
if to_unit == "Celsius":
|
18 |
+
return celsius
|
19 |
+
elif to_unit == "Fahrenheit":
|
20 |
+
return (celsius * 9/5) + 32
|
21 |
+
elif to_unit == "Kelvin":
|
22 |
+
return celsius + 273.15
|
23 |
+
|
24 |
+
# Streamlit UI
|
25 |
+
st.set_page_config(page_title="Temperature Converter", layout="centered")
|
26 |
+
|
27 |
st.title("🌡️ Temperature Converter")
|
28 |
|
29 |
+
col1, col2 = st.columns(2)
|
30 |
+
|
31 |
+
with col1:
|
32 |
+
from_unit = st.selectbox("From Unit", ["Celsius", "Fahrenheit", "Kelvin"])
|
33 |
+
with col2:
|
34 |
+
to_unit = st.selectbox("To Unit", ["Celsius", "Fahrenheit", "Kelvin"])
|
35 |
+
|
36 |
+
temp_value = st.slider("Select Temperature", min_value=0.0, max_value=500.0, step=0.1)
|
37 |
+
|
38 |
+
converted = convert_temperature(temp_value, from_unit, to_unit)
|
39 |
+
|
40 |
+
st.markdown(f"### 🔁 Converted Temperature: **{converted:.2f} {to_unit}**")
|
41 |
+
|
42 |
+
|
|
|
|
|
|
|
|
|
|