dotBlood / app.py
kedimestan's picture
Update app.py
ca1f7a3 verified
raw
history blame
1.45 kB
import gradio as gr
import pandas as pd
import matplotlib.pyplot as plt
def update_dropdowns(file):
if file is None:
return gr.Dropdown(choices=[]), gr.Dropdown(choices=[])
df = pd.read_csv(file)
columns = list(df.columns)
return gr.Dropdown(choices=columns), gr.Dropdown(choices=columns)
def create_scatter_plot(file, x_col, y_col):
if not file or not x_col or not y_col:
return None
df = pd.read_csv(file)
plt.figure(figsize=(10, 6))
plt.scatter(df[x_col], df[y_col])
plt.title(f"{x_col} vs {y_col}")
plt.xlabel(x_col)
plt.ylabel(y_col)
plt.grid(True)
plt.savefig("scatter_plot.png")
return "scatter_plot.png"
with gr.Blocks() as app:
gr.Markdown("# CSV Veri Görselleştirme Aracı")
with gr.Row():
csv_file = gr.File(label="CSV Dosyası Yükle", type="filepath")
with gr.Row():
x_axis = gr.Dropdown(label="X Ekseni Parametresi", interactive=True)
y_axis = gr.Dropdown(label="Y Ekseni Parametresi", interactive=True)
plot_button = gr.Button("Grafiği Oluştur")
with gr.Row():
plot_output = gr.Image(label="Scatter Plot")
csv_file.change(
fn=update_dropdowns,
inputs=csv_file,
outputs=[x_axis, y_axis]
)
plot_button.click(
fn=create_scatter_plot,
inputs=[csv_file, x_axis, y_axis],
outputs=plot_output
)
app.launch()