Spaces:
Build error
Build error
Update app.py
Browse files1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950# Import the necessary librariesimport gradio as gr # Import Gradio for creating the user interface
# Define a dictionary with color names and their corresponding hex codescolor_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 codedef 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 interfacewith 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 Faceapp.launch() # Launches the Gradio appapp.py+50