import cv2 import numpy as np import streamlit as st from sklearn.cluster import KMeans def get_dominant_color(image, k=1): image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) image = image.reshape((-1, 3)) kmeans = KMeans(n_clusters=k, random_state=0, n_init=10) kmeans.fit(image) dominant_color = kmeans.cluster_centers_[0].astype(int) return tuple(dominant_color) def is_warm_or_cool(color): r, g, b = color warm = (r > g and r > b) return "Warm" if warm else "Cool" def complementary_color(color): r, g, b = color return (255 - r, 255 - g, 255 - b) st.title("VQA for Colors and Color Theory") uploaded_file = st.file_uploader("Upload an image", type=["jpg", "png", "jpeg"]) if uploaded_file is not None: file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8) image = cv2.imdecode(file_bytes, cv2.IMREAD_COLOR) dominant = get_dominant_color(image) comp_color = complementary_color(dominant) st.image(cv2.cvtColor(image, cv2.COLOR_BGR2RGB), caption="Uploaded Image", use_column_width=True) st.write(f"**Dominant Color:** {dominant}") st.write(f"**Temperature:** This is a {is_warm_or_cool(dominant)} color.") st.write(f"**Complementary Color:** {comp_color}")