aaqibkhan039 commited on
Commit
e1cabe7
·
verified ·
1 Parent(s): 22c3367

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -37
app.py CHANGED
@@ -1,52 +1,66 @@
1
  import streamlit as st
2
 
3
- # Page configuration
4
- st.set_page_config(page_title="Temperature Converter", page_icon="🌡️", layout="centered")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- # Styling
7
  st.markdown(
8
  """
9
  <style>
10
- body {
11
- background-color: #f4f4f4;
12
- }
13
- .stApp {
14
- background: #ffffff;
15
- padding: 2rem;
16
- border-radius: 10px;
17
- box-shadow: 0px 0px 20px rgba(0, 0, 0, 0.1);
18
- text-align: center;
19
- }
 
 
 
 
 
 
 
 
 
 
 
 
20
  </style>
21
  """,
22
  unsafe_allow_html=True
23
  )
24
 
25
- # Title
26
- st.title("🌡️ Temperature Converter")
27
-
28
- # Temperature conversion function
29
- def convert_temperature(value, from_unit, to_unit):
30
- if from_unit == to_unit:
31
- return value
32
- elif from_unit == "Celsius":
33
- return value * 9/5 + 32 if to_unit == "Fahrenheit" else value + 273.15
34
- elif from_unit == "Fahrenheit":
35
- return (value - 32) * 5/9 if to_unit == "Celsius" else (value - 32) * 5/9 + 273.15
36
- elif from_unit == "Kelvin":
37
- return value - 273.15 if to_unit == "Celsius" else (value - 273.15) * 9/5 + 32
38
-
39
- # User input
40
- temperature = st.number_input("Enter Temperature:", value=0.0, format="%.2f")
41
 
42
- # Unit selection
43
- from_unit = st.selectbox("Convert from:", ["Celsius", "Fahrenheit", "Kelvin"])
44
- to_unit = st.selectbox("Convert to:", ["Celsius", "Fahrenheit", "Kelvin"])
45
 
46
- # Convert button
47
  if st.button("Convert"):
48
- result = convert_temperature(temperature, from_unit, to_unit)
49
- st.success(f"Converted Temperature: {result:.2f} {to_unit}")
 
 
 
 
 
 
50
 
51
- # Footer
52
- st.markdown("<small>Created with ❤️ using Streamlit</small>", unsafe_allow_html=True)
 
1
  import streamlit as st
2
 
3
+ def convert_temperature(value, unit):
4
+ if unit == "Celsius":
5
+ fahrenheit = (value * 9/5) + 32
6
+ kelvin = value + 273.15
7
+ return fahrenheit, kelvin
8
+ elif unit == "Fahrenheit":
9
+ celsius = (value - 32) * 5/9
10
+ kelvin = celsius + 273.15
11
+ return celsius, kelvin
12
+ elif unit == "Kelvin":
13
+ celsius = value - 273.15
14
+ fahrenheit = (celsius * 9/5) + 32
15
+ return celsius, fahrenheit
16
+
17
+ # Streamlit App Design
18
+ st.set_page_config(page_title="Temperature Converter", page_icon="🌡", layout="centered")
19
 
 
20
  st.markdown(
21
  """
22
  <style>
23
+ body {
24
+ background: linear-gradient(to right, #4A90E2, #145DA0);
25
+ color: white;
26
+ }
27
+ .stApp {
28
+ background-color: rgba(255, 255, 255, 0.1);
29
+ padding: 20px;
30
+ border-radius: 10px;
31
+ box-shadow: 0px 0px 10px rgba(255, 255, 255, 0.3);
32
+ color: white;
33
+ }
34
+ .stButton>button {
35
+ background-color: #FF5733;
36
+ color: white;
37
+ font-size: 16px;
38
+ border-radius: 8px;
39
+ }
40
+ .stNumberInput input {
41
+ background-color: white;
42
+ color: black;
43
+ border-radius: 5px;
44
+ }
45
  </style>
46
  """,
47
  unsafe_allow_html=True
48
  )
49
 
50
+ st.title("🌡 Temperature Converter")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
 
52
+ # Input Section
53
+ unit = st.selectbox("Select the unit of the input temperature:", ["Celsius", "Fahrenheit", "Kelvin"])
54
+ value = st.number_input("Enter the temperature value:", format="%.2f")
55
 
 
56
  if st.button("Convert"):
57
+ result1, result2 = convert_temperature(value, unit)
58
+
59
+ if unit == "Celsius":
60
+ st.success(f"{value}°C = {result1:.2f}°F = {result2:.2f}K")
61
+ elif unit == "Fahrenheit":
62
+ st.success(f"{value}°F = {result1:.2f}°C = {result2:.2f}K")
63
+ elif unit == "Kelvin":
64
+ st.success(f"{value}K = {result1:.2f}°C = {result2:.2f}°F")
65
 
66
+ st.markdown("**Made with ❤️ using Streamlit**")