Inam65's picture
Create app.py
071dbaf verified
import streamlit as st
st.set_page_config(page_title="Color Blender", layout="centered")
st.title("🎨 Color Blender")
st.markdown("Select two colors to blend and see the result!")
# Color input
color1 = st.color_picker("Pick Color 1", "#FF0000")
color2 = st.color_picker("Pick Color 2", "#0000FF")
def hex_to_rgb(hex_color):
hex_color = hex_color.lstrip('#')
return tuple(int(hex_color[i:i+2], 16) for i in (0, 2 ,4))
def rgb_to_hex(rgb):
return '#{:02x}{:02x}{:02x}'.format(*rgb)
def blend_colors(c1, c2):
rgb1 = hex_to_rgb(c1)
rgb2 = hex_to_rgb(c2)
blended_rgb = tuple((rgb1[i] + rgb2[i]) // 2 for i in range(3))
return rgb_to_hex(blended_rgb)
# Blend and display
if st.button("Blend Colors"):
blended_color = blend_colors(color1, color2)
st.markdown(f"**Blended Color:** `{blended_color}`")
st.markdown(
f'<div style="width:100px;height:100px;background-color:{blended_color};border-radius:8px;border:1px solid #ccc;"></div>',
unsafe_allow_html=True
)