Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
# Title of the App
|
4 |
+
st.title("Temperature Converter")
|
5 |
+
|
6 |
+
# Function to convert temperature
|
7 |
+
def convert_temperature(value, from_unit, to_unit):
|
8 |
+
if from_unit == 'Celsius':
|
9 |
+
if to_unit == 'Fahrenheit':
|
10 |
+
return (value * 9/5) + 32
|
11 |
+
elif to_unit == 'Kelvin':
|
12 |
+
return value + 273.15
|
13 |
+
elif from_unit == 'Fahrenheit':
|
14 |
+
if to_unit == 'Celsius':
|
15 |
+
return (value - 32) * 5/9
|
16 |
+
elif to_unit == 'Kelvin':
|
17 |
+
return (value - 32) * 5/9 + 273.15
|
18 |
+
elif from_unit == 'Kelvin':
|
19 |
+
if to_unit == 'Celsius':
|
20 |
+
return value - 273.15
|
21 |
+
elif to_unit == 'Fahrenheit':
|
22 |
+
return (value - 273.15) * 9/5 + 32
|
23 |
+
return value
|
24 |
+
|
25 |
+
# Input fields for the app
|
26 |
+
st.header("Temperature Conversion")
|
27 |
+
|
28 |
+
# Taking input from the user
|
29 |
+
value = st.number_input("Enter the temperature value:", value=0.0)
|
30 |
+
from_unit = st.selectbox("Select the unit to convert from", ['Celsius', 'Fahrenheit', 'Kelvin'])
|
31 |
+
to_unit = st.selectbox("Select the unit to convert to", ['Celsius', 'Fahrenheit', 'Kelvin'])
|
32 |
+
|
33 |
+
# Perform conversion and display result
|
34 |
+
if st.button("Convert"):
|
35 |
+
result = convert_temperature(value, from_unit, to_unit)
|
36 |
+
st.success(f"{value} {from_unit} is equal to {result} {to_unit}")
|