Team Ai
Apppublic

kubotahi/sandbox_matplotlib

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
app.py46 linesDownload Raw Back to root
1import gradio as gr2import pandas as pd3import numpy as np4import matplotlib.pyplot as plt5 6 7def plot_graph(file):8    df = pd.read_csv(file.name, low_memory=False, encoding='UTF-8')9 10    x = np.ravel(df["x"]).tolist()11    y = np.ravel(df["y"]).tolist()12    13    fig, ax = plt.subplots(figsize=(12,6), dpi=72)14 15 16    ax.plot(x, y)17    18    plt.xticks(fontsize=10, rotation=-90)19    plt.yticks(fontsize=10)20    plt.ylim(bottom=0)21 22    plt.tight_layout()23    24    ax.set_axisbelow(True)25    plt.grid(True)26    27    plot_filename = 'graph.png'28    plt.savefig(plot_filename)29    plt.close()30    31    return plot_filename32 33 34examples = [35    ["sample.csv"],36]37 38interface = gr.Interface(39    fn=plot_graph,40    inputs=gr.File(label="Upload CSV File"),41    outputs=gr.Image(type="filepath", label="Generated Graph"),42    title="Sandbox Matplotlib",43    examples=examples44)45 46interface.launch()