Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
# Function to convert Celsius to other units
|
4 |
+
def convert_temperature(celsius):
|
5 |
+
fahrenheit = (celsius * 9/5) + 32
|
6 |
+
kelvin = celsius + 273.15
|
7 |
+
return fahrenheit, kelvin
|
8 |
+
|
9 |
+
# Streamlit UI setup
|
10 |
+
st.set_page_config(page_title="Temperature Converter", layout="wide")
|
11 |
+
|
12 |
+
# Title and Description
|
13 |
+
st.title("Interactive Temperature Converter")
|
14 |
+
st.markdown("### Convert temperatures between Celsius, Fahrenheit, and Kelvin")
|
15 |
+
|
16 |
+
# Create columns for layout
|
17 |
+
col1, col2, col3 = st.columns(3)
|
18 |
+
|
19 |
+
# Column 1: User input for Celsius temperature
|
20 |
+
with col1:
|
21 |
+
celsius = st.number_input("Enter temperature in Celsius:", value=0, step=1)
|
22 |
+
|
23 |
+
# Column 2: Converted temperatures
|
24 |
+
with col2:
|
25 |
+
if celsius is not None:
|
26 |
+
fahrenheit, kelvin = convert_temperature(celsius)
|
27 |
+
st.subheader("Converted Values:")
|
28 |
+
st.write(f"Fahrenheit: {fahrenheit:.2f} °F")
|
29 |
+
st.write(f"Kelvin: {kelvin:.2f} K")
|
30 |
+
|
31 |
+
# Column 3: User input for Fahrenheit temperature (Optional)
|
32 |
+
with col3:
|
33 |
+
fahrenheit_input = st.number_input("Enter temperature in Fahrenheit:", value=32, step=1)
|
34 |
+
|
35 |
+
if fahrenheit_input is not None:
|
36 |
+
celsius_from_fahrenheit = (fahrenheit_input - 32) * 5/9
|
37 |
+
kelvin_from_fahrenheit = (fahrenheit_input - 32) * 5/9 + 273.15
|
38 |
+
st.subheader("Converted from Fahrenheit:")
|
39 |
+
st.write(f"Celsius: {celsius_from_fahrenheit:.2f} °C")
|
40 |
+
st.write(f"Kelvin: {kelvin_from_fahrenheit:.2f} K")
|
41 |
+
|
42 |
+
# Footer
|
43 |
+
st.markdown("---")
|
44 |
+
st.markdown("Created by [Your Name].")
|