amasood commited on
Commit
c549026
·
verified ·
1 Parent(s): 503ebe7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +62 -26
app.py CHANGED
@@ -22,12 +22,23 @@ def kelvin_to_fahrenheit(kelvin):
22
  return celsius_to_fahrenheit(celsius)
23
 
24
  # Streamlit app
25
- st.title("Temperature Conversion App")
26
- st.write("Convert temperatures between Celsius, Fahrenheit, and Kelvin.")
 
 
 
 
 
 
 
 
 
 
27
 
28
- # User input
29
- conversion_type = st.selectbox(
30
- "Select conversion type:",
 
31
  (
32
  "Celsius to Fahrenheit",
33
  "Fahrenheit to Celsius",
@@ -38,24 +49,49 @@ conversion_type = st.selectbox(
38
  )
39
  )
40
 
41
- temperature_input = st.number_input("Enter the temperature value:", format="%.2f")
42
-
43
- # Perform conversion
44
- if conversion_type == "Celsius to Fahrenheit":
45
- converted_temp = celsius_to_fahrenheit(temperature_input)
46
- st.write(f"{temperature_input}°C is equal to {converted_temp:.2f}°F.")
47
- elif conversion_type == "Fahrenheit to Celsius":
48
- converted_temp = fahrenheit_to_celsius(temperature_input)
49
- st.write(f"{temperature_input}°F is equal to {converted_temp:.2f}°C.")
50
- elif conversion_type == "Celsius to Kelvin":
51
- converted_temp = celsius_to_kelvin(temperature_input)
52
- st.write(f"{temperature_input}°C is equal to {converted_temp:.2f}K.")
53
- elif conversion_type == "Kelvin to Celsius":
54
- converted_temp = kelvin_to_celsius(temperature_input)
55
- st.write(f"{temperature_input}K is equal to {converted_temp:.2f}°C.")
56
- elif conversion_type == "Fahrenheit to Kelvin":
57
- converted_temp = fahrenheit_to_kelvin(temperature_input)
58
- st.write(f"{temperature_input}°F is equal to {converted_temp:.2f}K.")
59
- elif conversion_type == "Kelvin to Fahrenheit":
60
- converted_temp = kelvin_to_fahrenheit(temperature_input)
61
- st.write(f"{temperature_input}K is equal to {converted_temp:.2f}°F.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  return celsius_to_fahrenheit(celsius)
23
 
24
  # Streamlit app
25
+ st.set_page_config(
26
+ page_title="Temperature Converter",
27
+ page_icon="🌡️",
28
+ layout="centered"
29
+ )
30
+
31
+ # App title with icon
32
+ st.markdown(
33
+ "<h1 style='text-align: center; color: #FF5733;'>🌡️ Temperature Conversion App</h1>",
34
+ unsafe_allow_html=True
35
+ )
36
+ st.write("Convert temperatures between Celsius, Fahrenheit, and Kelvin with ease!")
37
 
38
+ # Sidebar for user input
39
+ st.sidebar.header("Conversion Options")
40
+ conversion_type = st.sidebar.radio(
41
+ "Choose a conversion type:",
42
  (
43
  "Celsius to Fahrenheit",
44
  "Fahrenheit to Celsius",
 
49
  )
50
  )
51
 
52
+ st.sidebar.markdown(
53
+ "<hr style='border: 1px solid #FF5733;'>",
54
+ unsafe_allow_html=True
55
+ )
56
+
57
+ temperature_input = st.sidebar.number_input(
58
+ "Enter the temperature value:",
59
+ format="%.2f"
60
+ )
61
+
62
+ # Add a button for conversion
63
+ if st.sidebar.button("Convert"):
64
+ if conversion_type == "Celsius to Fahrenheit":
65
+ converted_temp = celsius_to_fahrenheit(temperature_input)
66
+ result = f"{temperature_input}°C is equal to {converted_temp:.2f}°F."
67
+ elif conversion_type == "Fahrenheit to Celsius":
68
+ converted_temp = fahrenheit_to_celsius(temperature_input)
69
+ result = f"{temperature_input}°F is equal to {converted_temp:.2f}°C."
70
+ elif conversion_type == "Celsius to Kelvin":
71
+ converted_temp = celsius_to_kelvin(temperature_input)
72
+ result = f"{temperature_input}°C is equal to {converted_temp:.2f}K."
73
+ elif conversion_type == "Kelvin to Celsius":
74
+ converted_temp = kelvin_to_celsius(temperature_input)
75
+ result = f"{temperature_input}K is equal to {converted_temp:.2f}°C."
76
+ elif conversion_type == "Fahrenheit to Kelvin":
77
+ converted_temp = fahrenheit_to_kelvin(temperature_input)
78
+ result = f"{temperature_input}°F is equal to {converted_temp:.2f}K."
79
+ elif conversion_type == "Kelvin to Fahrenheit":
80
+ converted_temp = kelvin_to_fahrenheit(temperature_input)
81
+ result = f"{temperature_input}K is equal to {converted_temp:.2f}°F."
82
+
83
+ # Display result with styled text
84
+ st.markdown(
85
+ f"<h3 style='text-align: center; color: #33A1FF;'>{result}</h3>",
86
+ unsafe_allow_html=True
87
+ )
88
+
89
+ # Footer
90
+ st.markdown(
91
+ "<hr style='border: 1px solid #FF5733;'>",
92
+ unsafe_allow_html=True
93
+ )
94
+ st.markdown(
95
+ "<p style='text-align: center;'>Made with ❤️ using Streamlit</p>",
96
+ unsafe_allow_html=True
97
+ )