Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,33 +1,63 @@
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
-
from PIL import Image # For image processing
|
| 3 |
|
| 4 |
st.set_page_config(page_title="Temperature Converter", page_icon=":thermometer:", layout="wide")
|
| 5 |
|
| 6 |
-
# Custom CSS for
|
| 7 |
st.markdown(
|
| 8 |
"""
|
| 9 |
<style>
|
| 10 |
body {
|
| 11 |
-
font-family: '
|
| 12 |
-
background:
|
| 13 |
-
color: #333;
|
| 14 |
}
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
| 20 |
}
|
| 21 |
-
.
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
border-radius: 5px;
|
| 25 |
-
|
|
|
|
| 26 |
}
|
| 27 |
-
.
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
}
|
| 32 |
</style>
|
| 33 |
""",
|
|
@@ -37,42 +67,24 @@ st.markdown(
|
|
| 37 |
st.title("Temperature Converter")
|
| 38 |
|
| 39 |
with st.container() as converter_container:
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
|
| 42 |
|
| 43 |
col1, col2 = st.columns([1, 1])
|
| 44 |
|
| 45 |
with col1:
|
| 46 |
-
st.
|
| 47 |
temperature = st.number_input("Temperature", value=0.0)
|
| 48 |
unit_from = st.selectbox("From", ["Celsius", "Fahrenheit", "Kelvin"])
|
| 49 |
|
| 50 |
-
# Unit Images (Input Side - REPLACE image URLs or use local files)
|
| 51 |
-
st.markdown("<div class='unit-image-container'>")
|
| 52 |
-
if unit_from == "Celsius":
|
| 53 |
-
st.markdown("<img class='unit-image' src='https://upload.wikimedia.org/wikipedia/commons/thumb/6/6c/Celsius_scale.svg/1200px-Celsius_scale.svg.png' alt='Celsius'>", unsafe_allow_html=True) # Example URL - REPLACE THIS
|
| 54 |
-
elif unit_from == "Fahrenheit":
|
| 55 |
-
st.markdown("<img class='unit-image' src='https://upload.wikimedia.org/wikipedia/commons/thumb/9/9b/Fahrenheit_scale.svg/1200px-Fahrenheit_scale.svg.png' alt='Fahrenheit'>", unsafe_allow_html=True) # Example URL - REPLACE THIS
|
| 56 |
-
elif unit_from == "Kelvin":
|
| 57 |
-
st.markdown("<img class='unit-image' src='https://upload.wikimedia.org/wikipedia/commons/thumb/a/af/Kelvin_scale.svg/1200px-Kelvin_scale.svg.png' alt='Kelvin'>", unsafe_allow_html=True) # Example URL - REPLACE THIS
|
| 58 |
-
st.markdown("</div>")
|
| 59 |
-
|
| 60 |
-
|
| 61 |
with col2:
|
| 62 |
-
st.
|
| 63 |
unit_to = st.selectbox("To", ["Celsius", "Fahrenheit", "Kelvin"])
|
| 64 |
|
| 65 |
-
# Unit Images (Output Side - REPLACE image URLs or use local files)
|
| 66 |
-
st.markdown("<div class='unit-image-container'>")
|
| 67 |
-
if unit_to == "Celsius":
|
| 68 |
-
st.markdown("<img class='unit-image' src='https://upload.wikimedia.org/wikipedia/commons/thumb/6/6c/Celsius_scale.svg/1200px-Celsius_scale.svg.png' alt='Celsius'>", unsafe_allow_html=True) # Example URL - REPLACE THIS
|
| 69 |
-
elif unit_to == "Fahrenheit":
|
| 70 |
-
st.markdown("<img class='unit-image' src='https://upload.wikimedia.org/wikipedia/commons/thumb/9/9b/Fahrenheit_scale.svg/1200px-Fahrenheit_scale.svg.png' alt='Fahrenheit'>", unsafe_allow_html=True) # Example URL - REPLACE THIS
|
| 71 |
-
elif unit_to == "Kelvin":
|
| 72 |
-
st.markdown("<img class='unit-image' src='https://upload.wikimedia.org/wikipedia/commons/thumb/a/af/Kelvin_scale.svg/1200px-Kelvin_scale.svg.png' alt='Kelvin'>", unsafe_allow_html=True) # Example URL - REPLACE THIS
|
| 73 |
-
st.markdown("</div>")
|
| 74 |
-
|
| 75 |
if st.button("Convert"):
|
|
|
|
| 76 |
if unit_from == unit_to:
|
| 77 |
result = temperature
|
| 78 |
elif unit_from == "Celsius" and unit_to == "Fahrenheit":
|
|
@@ -90,22 +102,8 @@ with st.container() as converter_container:
|
|
| 90 |
|
| 91 |
st.markdown(f"<div class='result-area'>Result: {result:.2f} {unit_to}</div>", unsafe_allow_html=True)
|
| 92 |
|
| 93 |
-
# Image Upload (Optional - for local development)
|
| 94 |
-
st.subheader("Upload Image (Optional)")
|
| 95 |
-
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
| 96 |
-
|
| 97 |
-
if uploaded_file is not None:
|
| 98 |
-
image = Image.open(uploaded_file)
|
| 99 |
-
st.image(image, caption="Uploaded Image", use_column_width=True)
|
| 100 |
-
|
| 101 |
-
# (Optional) Save the uploaded image (create 'uploads' directory first)
|
| 102 |
-
# import os
|
| 103 |
-
# if not os.path.exists("uploads"):
|
| 104 |
-
# os.makedirs("uploads")
|
| 105 |
-
# with open(os.path.join("uploads", uploaded_file.name), "wb") as f:
|
| 106 |
-
# f.write(uploaded_file.getbuffer())
|
| 107 |
-
# st.success("Image saved!")
|
| 108 |
|
|
|
|
| 109 |
st.markdown("<p class='quote'>\"The only way to do great work is to love what you do.\" - Steve Jobs</p>", unsafe_allow_html=True)
|
| 110 |
|
| 111 |
st.markdown("---")
|
|
|
|
| 1 |
+
# app.py
|
| 2 |
import streamlit as st
|
|
|
|
| 3 |
|
| 4 |
st.set_page_config(page_title="Temperature Converter", page_icon=":thermometer:", layout="wide")
|
| 5 |
|
| 6 |
+
# Custom CSS for styling
|
| 7 |
st.markdown(
|
| 8 |
"""
|
| 9 |
<style>
|
| 10 |
body {
|
| 11 |
+
font-family: 'Arial', sans-serif;
|
| 12 |
+
background-color: #f4f4f4;
|
|
|
|
| 13 |
}
|
| 14 |
+
.converter-container {
|
| 15 |
+
border: 1px solid #ddd;
|
| 16 |
+
padding: 30px; /* Increased padding */
|
| 17 |
+
border-radius: 10px;
|
| 18 |
+
box-shadow: 5px 5px 15px rgba(0, 0, 0, 0.1);
|
| 19 |
+
background-color: white;
|
| 20 |
+
max-width: 700px; /* Increased container width */
|
| 21 |
+
margin: 20px auto; /* Added margin top/bottom */
|
| 22 |
}
|
| 23 |
+
.input-group {
|
| 24 |
+
margin-bottom: 20px; /* Increased margin */
|
| 25 |
+
}
|
| 26 |
+
.input-group label {
|
| 27 |
+
font-weight: bold;
|
| 28 |
+
margin-bottom: 8px;
|
| 29 |
+
}
|
| 30 |
+
.stButton>button {
|
| 31 |
+
background-color: #007bff;
|
| 32 |
+
color: white;
|
| 33 |
+
padding: 12px 20px;
|
| 34 |
+
border: none;
|
| 35 |
border-radius: 5px;
|
| 36 |
+
cursor: pointer;
|
| 37 |
+
width: 100%;
|
| 38 |
}
|
| 39 |
+
.stButton>button:hover {
|
| 40 |
+
background-color: #0056b3;
|
| 41 |
+
}
|
| 42 |
+
.result-area {
|
| 43 |
+
margin-top: 25px; /* Increased margin */
|
| 44 |
+
padding: 18px; /* Increased padding */
|
| 45 |
+
border: 1px solid #ddd;
|
| 46 |
+
border-radius: 5px;
|
| 47 |
+
background-color: #f9f9f9;
|
| 48 |
+
font-size: 1.2em;
|
| 49 |
+
font-weight: bold;
|
| 50 |
+
text-align: center; /* Center the result */
|
| 51 |
+
}
|
| 52 |
+
.quote {
|
| 53 |
+
font-style: italic;
|
| 54 |
+
color: #777;
|
| 55 |
+
margin-top: 20px;
|
| 56 |
+
text-align: center;
|
| 57 |
+
}
|
| 58 |
+
.image-container {
|
| 59 |
+
text-align: center; /* Center the image */
|
| 60 |
+
margin-bottom: 20px;
|
| 61 |
}
|
| 62 |
</style>
|
| 63 |
""",
|
|
|
|
| 67 |
st.title("Temperature Converter")
|
| 68 |
|
| 69 |
with st.container() as converter_container:
|
| 70 |
+
|
| 71 |
+
# Image (replace with your image URL or upload)
|
| 72 |
+
st.markdown("<div class='image-container'><img src='https://upload.wikimedia.org/wikipedia/commons/thumb/f/f9/Thermometer_showing_38_degree_Celsius.svg/1200px-Thermometer_showing_38_degree_Celsius.svg.png' alt='Thermometer' width='200'></div>", unsafe_allow_html=True)
|
| 73 |
+
|
| 74 |
|
| 75 |
col1, col2 = st.columns([1, 1])
|
| 76 |
|
| 77 |
with col1:
|
| 78 |
+
st.subheader("Input")
|
| 79 |
temperature = st.number_input("Temperature", value=0.0)
|
| 80 |
unit_from = st.selectbox("From", ["Celsius", "Fahrenheit", "Kelvin"])
|
| 81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
with col2:
|
| 83 |
+
st.subheader("Output")
|
| 84 |
unit_to = st.selectbox("To", ["Celsius", "Fahrenheit", "Kelvin"])
|
| 85 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
if st.button("Convert"):
|
| 87 |
+
# ... (Conversion logic remains the same)
|
| 88 |
if unit_from == unit_to:
|
| 89 |
result = temperature
|
| 90 |
elif unit_from == "Celsius" and unit_to == "Fahrenheit":
|
|
|
|
| 102 |
|
| 103 |
st.markdown(f"<div class='result-area'>Result: {result:.2f} {unit_to}</div>", unsafe_allow_html=True)
|
| 104 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
|
| 106 |
+
# Quote
|
| 107 |
st.markdown("<p class='quote'>\"The only way to do great work is to love what you do.\" - Steve Jobs</p>", unsafe_allow_html=True)
|
| 108 |
|
| 109 |
st.markdown("---")
|