Spaces:
Runtime error
Runtime error
| import streamlit as st | |
| # Function to change text color based on user input | |
| def change_text_color(text, color): | |
| # Apply HTML styling to change text color, set font size, and add a border | |
| styled_text = f'<div style="color:{color}; font-size: 32px; font-weight: bold; border: 2px solid {color}; padding: 10px;">{text}</div>' | |
| return styled_text | |
| # Streamlit app | |
| st.title("Text Color Changer") | |
| # Input text | |
| user_text = st.text_input("Enter your text:") | |
| # Predefined color selection | |
| st.subheader("Select text color:") | |
| # Expanded list of predefined color options | |
| color_options = [ | |
| "red", "blue", "green", "orange", "yellow", "purple", "pink", "brown", "gray", | |
| "cyan", "magenta", "violet", " indigo", "lime", "olive", "teal", "navy", "maroon", | |
| "aquamarine", "azure", "beige", "black", "fuchsia", "silver", "white", | |
| "lavender", "turquoise", "plum", "salmon", "sienna", "tomato", "wheat", "orchid", | |
| "thistle", "peru", "royalblue", "dodgerblue", "darkslategray", "darkseagreen", | |
| "darkred", "darkorange", "darkolivegreen", "darkmagenta", "darkkhaki", "darkgray", | |
| "darkcyan", "darkblue", "darkgoldenrod", "mediumblue", "mediumorchid", | |
| "cornflowerblue", "chocolate", "coral", "crimson", "forestgreen", "gainsboro", | |
| "goldenrod", "hotpink", "ivory", "khaki", "lawngreen", "lightcyan", "lightgrey", | |
| "lightpink", "lightsalmon", "lightseagreen", "lightskyblue", "lightslategray", | |
| "mediumaquamarine", "mediumslateblue", "mediumspringgreen", "midnightblue", | |
| "mistyrose", "moccasin", "navajowhite", "oldlace", "olivedrab", "orangered", | |
| "palevioletred", "peachpuff", "rebeccapurple", "rosybrown", "seagreen", | |
| "seashell", "slateblue", "slategray", "springgreen", "steelblue", "tan", | |
| "transparent", "wheat" | |
| ] | |
| # User can select a predefined color or input a custom color code | |
| selected_color = st.selectbox("Select a color:", color_options + ["Custom"]) | |
| if selected_color == "Custom": | |
| custom_color_code = st.color_picker("Choose a custom color:") | |
| selected_color = custom_color_code | |
| # Apply text color change and display | |
| styled_text = change_text_color(user_text, selected_color) | |
| st.markdown(styled_text, unsafe_allow_html=True) | |
| # Add a separate custom button | |
| if st.button("Customize Text Color"): | |
| selected_color = st.color_picker("Choose a custom color:") | |
| styled_text = change_text_color(user_text, selected_color) | |
| st.markdown(styled_text, unsafe_allow_html=True) | |