File size: 884 Bytes
04c179c
 
d9cfe10
04c179c
 
 
 
d9cfe10
 
f92ded4
 
04c179c
d9cfe10
4e04b0e
34438fc
4e04b0e
34438fc
b851abf
34438fc
 
 
b49bf9c
 
d9cfe10
04c179c
34438fc
4e04b0e
04c179c
 
d9cfe10
04c179c
 
 
 
9d4f6d2
04c179c
 
 
 
 
 
e86dabf
04c179c
 
 
 
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
import gradio as gr
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt


def plot_graph(file):
    df = pd.read_csv(file.name, low_memory=False, encoding='UTF-8')

    x = np.ravel(df["x"]).tolist()
    y = np.ravel(df["y"]).tolist()
    
    fig, ax = plt.subplots(figsize=(12,6), dpi=72)


    ax.plot(x, y)
    
    plt.xticks(fontsize=10, rotation=-90)
    plt.yticks(fontsize=10)
    plt.ylim(bottom=0)

    plt.tight_layout()
    
    ax.set_axisbelow(True)
    plt.grid(True)
    
    plot_filename = 'graph.png'
    plt.savefig(plot_filename)
    plt.close()
    
    return plot_filename


examples = [
    ["sample.csv"],
]

interface = gr.Interface(
    fn=plot_graph,
    inputs=gr.File(label="Upload CSV File"),
    outputs=gr.Image(type="filepath", label="Generated Graph"),
    title="Sandbox Matplotlib",
    examples=examples
)

interface.launch()