Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
|
| 3 |
+
st.set_page_config(page_title="Color Blender", layout="centered")
|
| 4 |
+
|
| 5 |
+
st.title("🎨 Color Blender")
|
| 6 |
+
st.markdown("Select two colors to blend and see the result!")
|
| 7 |
+
|
| 8 |
+
# Color input
|
| 9 |
+
color1 = st.color_picker("Pick Color 1", "#FF0000")
|
| 10 |
+
color2 = st.color_picker("Pick Color 2", "#0000FF")
|
| 11 |
+
|
| 12 |
+
def hex_to_rgb(hex_color):
|
| 13 |
+
hex_color = hex_color.lstrip('#')
|
| 14 |
+
return tuple(int(hex_color[i:i+2], 16) for i in (0, 2 ,4))
|
| 15 |
+
|
| 16 |
+
def rgb_to_hex(rgb):
|
| 17 |
+
return '#{:02x}{:02x}{:02x}'.format(*rgb)
|
| 18 |
+
|
| 19 |
+
def blend_colors(c1, c2):
|
| 20 |
+
rgb1 = hex_to_rgb(c1)
|
| 21 |
+
rgb2 = hex_to_rgb(c2)
|
| 22 |
+
blended_rgb = tuple((rgb1[i] + rgb2[i]) // 2 for i in range(3))
|
| 23 |
+
return rgb_to_hex(blended_rgb)
|
| 24 |
+
|
| 25 |
+
# Blend and display
|
| 26 |
+
if st.button("Blend Colors"):
|
| 27 |
+
blended_color = blend_colors(color1, color2)
|
| 28 |
+
st.markdown(f"**Blended Color:** `{blended_color}`")
|
| 29 |
+
st.markdown(
|
| 30 |
+
f'<div style="width:100px;height:100px;background-color:{blended_color};border-radius:8px;border:1px solid #ccc;"></div>',
|
| 31 |
+
unsafe_allow_html=True
|
| 32 |
+
)
|