Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,17 +2,45 @@ import streamlit as st
|
|
| 2 |
|
| 3 |
# Function to change text color based on user input
|
| 4 |
def change_text_color(text, color):
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
|
|
|
| 8 |
|
| 9 |
-
# Streamlit app
|
| 10 |
st.title("Text Color Changer")
|
| 11 |
|
| 12 |
# Input text and color selection
|
| 13 |
user_text = st.text_input("Enter your text:")
|
| 14 |
-
selected_color = st.selectbox("Select text color:", ["red", "blue", "green", "orange"])
|
| 15 |
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
styled_text = change_text_color(user_text, selected_color)
|
| 18 |
-
st.markdown(styled_text, unsafe_allow_html=True)
|
|
|
|
| 2 |
|
| 3 |
# Function to change text color based on user input
|
| 4 |
def change_text_color(text, color):
|
| 5 |
+
# Apply HTML styling to change text color
|
| 6 |
+
styled_text = f'<span style="color:{color};">{text}</span>'
|
| 7 |
+
|
| 8 |
+
return styled_text
|
| 9 |
|
| 10 |
+
# Streamlit app
|
| 11 |
st.title("Text Color Changer")
|
| 12 |
|
| 13 |
# Input text and color selection
|
| 14 |
user_text = st.text_input("Enter your text:")
|
|
|
|
| 15 |
|
| 16 |
+
st.subheader("Select text color:")
|
| 17 |
+
|
| 18 |
+
# Expanded list of predefined color options
|
| 19 |
+
color_options = [
|
| 20 |
+
"red", "blue", "green", "orange", "yellow", "purple", "pink", "brown", "gray",
|
| 21 |
+
"cyan", "magenta", "violet", "indigo", "lime", "olive", "teal", "navy", "maroon",
|
| 22 |
+
"aquamarine", "azure", "beige", "black", "fuchsia", "silver", "white",
|
| 23 |
+
"lavender", "turquoise", "plum", "salmon", "sienna", "tomato", "wheat", "orchid",
|
| 24 |
+
"thistle", "peru", "royalblue", "dodgerblue", "darkslategray", "darkseagreen",
|
| 25 |
+
"darkred", "darkorange", "darkolivegreen", "darkmagenta", "darkkhaki", "darkgray",
|
| 26 |
+
"darkcyan", "darkblue", "darkgoldenrod", "mediumblue", "mediumorchid",
|
| 27 |
+
"cornflowerblue", "chocolate", "coral", "crimson", "forestgreen", "gainsboro",
|
| 28 |
+
"goldenrod", "hotpink", "ivory", "khaki", "lawngreen", "lightcyan", "lightgrey",
|
| 29 |
+
"lightpink", "lightsalmon", "lightseagreen", "lightskyblue", "lightslategray",
|
| 30 |
+
"mediumaquamarine", "mediumslateblue", "mediumspringgreen", "midnightblue",
|
| 31 |
+
"mistyrose", "moccasin", "navajowhite", "oldlace", "olivedrab", "orangered",
|
| 32 |
+
"palevioletred", "peachpuff", "rebeccapurple", "rosybrown", "seagreen",
|
| 33 |
+
"seashell", "slateblue", "slategray", "springgreen", "steelblue", "tan",
|
| 34 |
+
"transparent", "wheat"
|
| 35 |
+
]
|
| 36 |
+
|
| 37 |
+
# User can select a predefined color or input a custom color code
|
| 38 |
+
selected_color = st.selectbox("Select a color:", color_options + ["Custom"])
|
| 39 |
+
|
| 40 |
+
if selected_color == "Custom":
|
| 41 |
+
custom_color_code = st.text_input("Enter a custom color code (e.g., #RRGGBB or a color name):")
|
| 42 |
+
selected_color = custom_color_code
|
| 43 |
+
|
| 44 |
+
# Apply text color change and display
|
| 45 |
styled_text = change_text_color(user_text, selected_color)
|
| 46 |
+
st.markdown(styled_text, unsafe_allow_html=True)
|