Fixed invalid RGBA color issue (default to black)
Browse files5 unmodified lines678910119 unmodified lines2122232425262727 unmodified lines555657585960615 unmodified linesdef hex_to_rgb(hex_color):"""Convert HEX color (e.g., '#ff5733') to an RGB tuple for Matplotlib."""rgb = mcolors.hex2color(hex_color) # Convert HEX to RGBreturn rgb9 unmodified linesfunc = lambda x: eval(func_text, {"x": x, "np": np})y_values = func(x_values)# Convert HEX color to RGB before passing to Matplotlibrgb_color = hex_to_rgb(color)plt.plot(x_values, y_values, label=f"f(x) = {func_text}", color=rgb_color, linestyle=linestyle)27 unmodified linesx_min = gr.Number(label="X Min", value=-10)x_max = gr.Number(label="X Max", value=10)resolution = gr.Slider(10, 1000, step=10, label="Resolution", value=100)color = gr.ColorPicker(label="Line Color")linestyle = gr.Dropdown(["solid", "dashed", "dotted", "dashdot"], label="Line Style")grid = gr.Checkbox(label="Show Grid", value=True)submit_button = gr.Button("Plot Function")5 unmodified lines6789101112139 unmodified lines2324252627282927 unmodified lines575859606162635 unmodified linesdef hex_to_rgb(hex_color):"""Convert HEX color (e.g., '#ff5733') to an RGB tuple for Matplotlib."""if hex_color is None: # If no color is selected, default to blackhex_color = "#000000"rgb = mcolors.hex2color(hex_color) # Convert HEX to RGBreturn rgb9 unmodified linesfunc = lambda x: eval(func_text, {"x": x, "np": np})y_values = func(x_values)# Ensure a valid color is provided, defaulting to blackrgb_color = hex_to_rgb(color)plt.plot(x_values, y_values, label=f"f(x) = {func_text}", color=rgb_color, linestyle=linestyle)27 unmodified linesx_min = gr.Number(label="X Min", value=-10)x_max = gr.Number(label="X Max", value=10)resolution = gr.Slider(10, 1000, step=10, label="Resolution", value=100)color = gr.ColorPicker(label="Line Color", value="#000000") # Set default to blacklinestyle = gr.Dropdown(["solid", "dashed", "dotted", "dashdot"], label="Line Style")grid = gr.Checkbox(label="Show Grid", value=True)submit_button = gr.Button("Plot Function")
app.py+4-2