kubotahi's picture
Update app.py
b851abf verified
raw
history blame contribute delete
884 Bytes
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()