Spaces:
Runtime error
Runtime error
File size: 2,291 Bytes
c6379ae 9be415c e760057 b13bccc e43f165 b13bccc f305b38 e43f165 b13bccc e43f165 602a264 e43f165 e760057 e43f165 b13bccc e760057 e43f165 e760057 e43f165 f305b38 da71915 e760057 ee16303 e760057 ee16303 da71915 e43f165 e760057 9239ab3 b13bccc e760057 b13bccc e760057 9239ab3 e760057 e43f165 e760057 e43f165 b13bccc e760057 e43f165 e760057 e43f165 b13bccc e760057 e43f165 e760057 9239ab3 f305b38 b13bccc |
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
import gradio as gr
import pandas as pd
import plotly.express as px
def update_columns(csv_file):
if csv_file is None:
return gr.Dropdown(choices=[]), gr.Dropdown(choices=[])
df = pd.read_csv(csv_file.name)
numeric_cols = df.select_dtypes(include=['number']).columns.tolist()
return gr.Dropdown(choices=numeric_cols), gr.Dropdown(choices=numeric_cols)
def create_scatter_plot(csv_file, x_col, y_col):
if csv_file is None or x_col is None or y_col is None:
return None, None
df = pd.read_csv(csv_file.name)
# Gradio ScatterPlot için uygun formatta veri hazırla
return (
gr.ScatterPlot(
value=df,
x=x_col,
y=y_col,
tooltip=df.columns.tolist(),
title="Interactive Scatter Plot",
color_legend_title="Values",
interactive=True,
brush_radius=5
),
df
)
def get_selected_points(evt: gr.SelectData, df):
if evt is None or df is None:
return pd.DataFrame()
# Seçilen indeksleri kullanarak verileri filtrele
selected_indices = [i["index"] for i in evt.selected]
return df.iloc[selected_indices]
with gr.Blocks() as app:
gr.Markdown("## 🔷 Polygon ile Veri Seçimi")
with gr.Row():
csv_upload = gr.UploadButton(label="CSV Yükle", file_types=[".csv"])
x_dropdown = gr.Dropdown(label="X Ekseni")
y_dropdown = gr.Dropdown(label="Y Ekseni")
with gr.Row():
scatter_plot = gr.ScatterPlot(interactive=True, brush_radius=5)
selected_table = gr.DataFrame(label="Seçilen Veriler")
df_state = gr.State()
csv_upload.upload(
fn=update_columns,
inputs=csv_upload,
outputs=[x_dropdown, y_dropdown]
)
x_dropdown.change(
fn=create_scatter_plot,
inputs=[csv_upload, x_dropdown, y_dropdown],
outputs=[scatter_plot, df_state]
)
y_dropdown.change(
fn=create_scatter_plot,
inputs=[csv_upload, x_dropdown, y_dropdown],
outputs=[scatter_plot, df_state]
)
scatter_plot.select(
fn=get_selected_points,
inputs=df_state,
outputs=selected_table
)
if __name__ == "__main__":
app.launch() |