Spaces:
Build error

File size: 1,792 Bytes
8a2c34b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# Import the necessary libraries
import gradio as gr  # Import Gradio for creating the user interface

# Define a dictionary with color names and their corresponding hex codes
color_codes = {
    "red": "#FF0000",
    "blue": "#0000FF",
    "green": "#00FF00",
    "black": "#000000",
    "white": "#FFFFFF",
    "yellow": "#FFFF00",
    "purple": "#800080",
    "orange": "#FFA500",
    "pink": "#FFC0CB",
    "gray": "#808080",
    # Add additional colors as needed
}

# Define the function to retrieve the color code
def get_color_code(color_name):
    """
    Retrieves the hex color code based on the color name input by the user.
    If the color is not in the list, it returns a 'Color not found' message.
    """
    color_name = color_name.lower()  # Convert the color name to lowercase
    if color_name in color_codes:
        return color_codes[color_name]
    else:
        return "Color not found in the list. Try another color."

# Set up the Gradio interface
with gr.Blocks() as app:  # Creates the Gradio app interface
    # Title and description for the app
    gr.Markdown("<h1>Color Code Finder</h1>")
    gr.Markdown("Enter a color name to get its hex color code.")

    # Input box for the color name
    color_name_input = gr.Textbox(label="Enter color name:", placeholder="e.g., red, blue, green")
    
    # Output box for displaying the hex code
    color_code_output = gr.Textbox(label="Color Code", interactive=False)

    # Button to find the color code
    find_color_button = gr.Button("Find Color Code")
    
    # Define the button's action to call get_color_code and output the result
    find_color_button.click(fn=get_color_code, inputs=color_name_input, outputs=color_code_output)

# Launch the app on Hugging Face
app.launch()  # Launches the Gradio app