Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,93 +1,57 @@
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
-
|
4 |
|
5 |
-
def
|
6 |
-
|
7 |
-
|
8 |
-
def update_dropdowns(df):
|
9 |
-
if df is None or df.empty:
|
10 |
return gr.Dropdown(choices=[]), gr.Dropdown(choices=[])
|
11 |
-
|
|
|
12 |
return gr.Dropdown(choices=columns), gr.Dropdown(choices=columns)
|
13 |
|
14 |
-
def
|
15 |
-
if
|
16 |
return None
|
17 |
-
return {
|
18 |
-
"x": df[x_col].tolist(),
|
19 |
-
"y": df[y_col].tolist(),
|
20 |
-
"color": "blue",
|
21 |
-
"tooltip": df.columns.tolist(),
|
22 |
-
"x_title": x_col,
|
23 |
-
"y_title": y_col
|
24 |
-
}
|
25 |
-
|
26 |
-
def filter_points(event: gr.SelectData, df, x_col, y_col):
|
27 |
-
if df is None or x_col not in df.columns or y_col not in df.columns:
|
28 |
-
return pd.DataFrame()
|
29 |
-
|
30 |
-
if not hasattr(filter_points, "points"):
|
31 |
-
filter_points.points = []
|
32 |
|
33 |
-
|
34 |
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
|
|
37 |
|
38 |
-
|
39 |
-
|
40 |
-
mask = df[[x_col, y_col]].apply(
|
41 |
-
lambda row: polygon.contains(Point(row[x_col], row[y_col])),
|
42 |
-
axis=1
|
43 |
-
)
|
44 |
-
return df[mask]
|
45 |
-
finally:
|
46 |
-
filter_points.points = []
|
47 |
|
48 |
-
with gr.Blocks() as
|
49 |
-
gr.Markdown("
|
50 |
-
|
51 |
-
df_state = gr.State()
|
52 |
|
53 |
with gr.Row():
|
54 |
-
|
55 |
-
x_col = gr.Dropdown(label="2. X Sütunu Seç")
|
56 |
-
y_col = gr.Dropdown(label="3. Y Sütunu Seç")
|
57 |
-
|
58 |
-
plot = gr.ScatterPlot(
|
59 |
-
label="4. Lasso Tool ile Alan Seç",
|
60 |
-
show_label=True,
|
61 |
-
interactive=True
|
62 |
-
)
|
63 |
|
64 |
-
|
|
|
|
|
65 |
|
66 |
-
|
67 |
-
load_csv,
|
68 |
-
inputs=csv_upload,
|
69 |
-
outputs=df_state
|
70 |
-
).then(
|
71 |
-
update_dropdowns,
|
72 |
-
inputs=df_state,
|
73 |
-
outputs=[x_col, y_col]
|
74 |
-
)
|
75 |
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
outputs=plot
|
85 |
)
|
86 |
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
|
|
91 |
)
|
92 |
|
93 |
-
|
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
+
import matplotlib.pyplot as plt
|
4 |
|
5 |
+
def update_dropdowns(file):
|
6 |
+
if file is None:
|
|
|
|
|
|
|
7 |
return gr.Dropdown(choices=[]), gr.Dropdown(choices=[])
|
8 |
+
df = pd.read_csv(file.name)
|
9 |
+
columns = list(df.columns)
|
10 |
return gr.Dropdown(choices=columns), gr.Dropdown(choices=columns)
|
11 |
|
12 |
+
def create_scatter_plot(file, x_col, y_col):
|
13 |
+
if file is None or not x_col or not y_col:
|
14 |
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
+
df = pd.read_csv(file.name)
|
17 |
|
18 |
+
plt.figure(figsize=(10, 6))
|
19 |
+
plt.scatter(df[x_col], df[y_col])
|
20 |
+
plt.title(f"{x_col} vs {y_col}")
|
21 |
+
plt.xlabel(x_col)
|
22 |
+
plt.ylabel(y_col)
|
23 |
+
plt.grid(True)
|
24 |
|
25 |
+
plt.savefig("scatter_plot.png")
|
26 |
+
return "scatter_plot.png"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
+
with gr.Blocks() as app:
|
29 |
+
gr.Markdown("# CSV Veri Görselleştirme Aracı")
|
|
|
|
|
30 |
|
31 |
with gr.Row():
|
32 |
+
csv_file = gr.File(label="CSV Dosyası Yükle", type="file")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
+
with gr.Row():
|
35 |
+
x_axis = gr.Dropdown(label="X Ekseni Parametresi", interactive=True)
|
36 |
+
y_axis = gr.Dropdown(label="Y Ekseni Parametresi", interactive=True)
|
37 |
|
38 |
+
plot_button = gr.Button("Grafiği Oluştur")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
+
with gr.Row():
|
41 |
+
plot_output = gr.Image(label="Scatter Plot")
|
42 |
+
|
43 |
+
# Dropdown'ları güncelleme
|
44 |
+
csv_file.change(
|
45 |
+
fn=update_dropdowns,
|
46 |
+
inputs=csv_file,
|
47 |
+
outputs=[x_axis, y_axis]
|
|
|
48 |
)
|
49 |
|
50 |
+
# Plot oluşturma
|
51 |
+
plot_button.click(
|
52 |
+
fn=create_scatter_plot,
|
53 |
+
inputs=[csv_file, x_axis, y_axis],
|
54 |
+
outputs=plot_output
|
55 |
)
|
56 |
|
57 |
+
app.launch()
|