Sib83 commited on
Commit
aea6065
·
verified ·
1 Parent(s): 65c9117

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +71 -12
app.py CHANGED
@@ -1,9 +1,60 @@
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':
@@ -22,15 +73,23 @@ def convert_temperature(value, from_unit, to_unit):
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}")
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ import requests
3
 
4
+ # Title of the App with a background image and better UI
5
+ st.set_page_config(page_title="Temperature Converter", page_icon="🌡️", layout="wide")
6
 
7
+ # Custom CSS for improved UI
8
+ st.markdown("""
9
+ <style>
10
+ .main {
11
+ background-color: #F0F8FF;
12
+ }
13
+ .title {
14
+ color: #0044cc;
15
+ font-size: 40px;
16
+ font-weight: bold;
17
+ text-align: center;
18
+ }
19
+ .input-field {
20
+ background-color: #ffffff;
21
+ border: 2px solid #0044cc;
22
+ border-radius: 8px;
23
+ padding: 10px;
24
+ font-size: 18px;
25
+ }
26
+ .convert-btn {
27
+ background-color: #0044cc;
28
+ color: white;
29
+ font-size: 18px;
30
+ padding: 10px 20px;
31
+ border-radius: 5px;
32
+ }
33
+ .result-text {
34
+ font-size: 22px;
35
+ font-weight: bold;
36
+ color: #2e8b57;
37
+ text-align: center;
38
+ }
39
+ .footer {
40
+ text-align: center;
41
+ margin-top: 20px;
42
+ color: #888888;
43
+ font-size: 14px;
44
+ }
45
+ </style>
46
+ """, unsafe_allow_html=True)
47
+
48
+ # Display the title with temperature-themed animation
49
+ st.markdown('<div class="title">Temperature Converter App 🌡️</div>', unsafe_allow_html=True)
50
+
51
+ # 3D Animated Visualization - Embedding a rotating globe with temperature visuals
52
+ st.markdown("""
53
+ <h3 style="text-align:center;">Temperature across the globe 🌍</h3>
54
+ <iframe src="https://www.meteomatics.com/en/weather-forecast-3d-globe/" width="100%" height="500px"></iframe>
55
+ """, unsafe_allow_html=True)
56
+
57
+ # Conversion Logic for the temperature
58
  def convert_temperature(value, from_unit, to_unit):
59
  if from_unit == 'Celsius':
60
  if to_unit == 'Fahrenheit':
 
73
  return (value - 273.15) * 9/5 + 32
74
  return value
75
 
76
+ # Temperature input fields
77
+ st.header("Enter the values for conversion")
78
+ value = st.number_input("Enter temperature value:", value=0.0, step=0.1, format="%.1f", className="input-field")
79
 
80
+ # Selectboxes for units
81
+ from_unit = st.selectbox("Select the unit to convert from", ['Celsius', 'Fahrenheit', 'Kelvin'], key="from_unit")
82
+ to_unit = st.selectbox("Select the unit to convert to", ['Celsius', 'Fahrenheit', 'Kelvin'], key="to_unit")
 
83
 
84
+ # Submit button to perform conversion
85
+ if st.button("Convert", key="convert_btn", help="Click to convert the temperature", use_container_width=True):
86
  result = convert_temperature(value, from_unit, to_unit)
87
+ st.markdown(f'<div class="result-text">{value} {from_unit} is equal to {result} {to_unit}</div>', unsafe_allow_html=True)
88
+
89
+ # Footer - A simple message
90
+ st.markdown("""
91
+ <div class="footer">
92
+ Made with ❤️ by [Your Name]. Temperature converter app.
93
+ </div>
94
+ """, unsafe_allow_html=True)
95
+