import matplotlib.pyplot as plt import numpy as np import gradio as gr def plot_forecast(final_year, cryptocurrencies, noise, show_legend, point_style, line_colors): start_year = 2020 x = np.arange(start_year, final_year + 1) year_count = x.shape[0] plt_format = ({"cross": "X", "line": "-", "circle": "o--"})[point_style] fig = plt.figure() ax = fig.add_subplot(111) for i, crypto in enumerate(cryptocurrencies): series = np.arange(0, year_count, dtype=float) series = series**2 * (i + 1) series += np.random.rand(year_count) * noise ax.plot(x, series, plt_format, label=crypto, color=line_colors[i % len(line_colors)]) if show_legend: plt.legend() ax.set_xlabel("Year") ax.set_ylabel("Value") ax.set_title(f"Cryptocurrency Forecast from {start_year} to {final_year}") return fig # Create a color palette for the plot def generate_color_palette(): return ["#1f77b4", "#ff7f0e", "#2ca02c", "#d62728", "#9467bd"] demo = gr.Interface( plot_forecast, [ gr.Radio([2025, 2030, 2035, 2040], label="Project to:", info="Select the forecast year."), gr.CheckboxGroup(["Bitcoin", "Ethereum", "Litecoin"], label="Cryptocurrency Selection", info="Choose which cryptocurrencies to forecast."), gr.Slider(1, 100, label="Noise Level", info="Adjust the level of random noise added to the data."), gr.Checkbox(label="Show Legend", info="Toggle the display of the legend."), gr.Dropdown(["cross", "line", "circle"], label="Point Style", info="Choose the marker style for the plot."), gr.ColorPicker(label="Line Colors", value="#1f77b4", info="Choose line colors for the plot.", show_alpha=False), # Color picker for lines ], outputs=gr.Plot(label="Forecast Plot", format="png"), layout="vertical", # Improved layout for better organization title="Cryptocurrency Forecasting Tool", # Added title theme="huggingface", # Applying a predefined theme for better look and feel ) if __name__ == "__main__": demo.launch(show_error=True)