kedimestan commited on
Commit
49eba4a
·
verified ·
1 Parent(s): 9445aeb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -20
app.py CHANGED
@@ -1,6 +1,5 @@
1
  import gradio as gr
2
  import pandas as pd
3
- import numpy as np
4
  from shapely.geometry import Point, Polygon
5
 
6
  def load_csv(file):
@@ -16,35 +15,31 @@ def create_plot(df, x_col, y_col):
16
  "x": df[x_col].tolist(),
17
  "y": df[y_col].tolist(),
18
  "color": "blue",
19
- "tooltip": df.columns.tolist()
 
 
20
  }
21
 
22
  def filter_points(event: gr.SelectData, df, x_col, y_col):
23
  if not hasattr(filter_points, "points"):
24
  filter_points.points = []
25
 
26
- # Yeni noktayı ekle
27
  filter_points.points.append((event.x, event.y))
28
 
29
- # 3'ten az nokta varsa boş dön
30
  if len(filter_points.points) < 3:
31
  return pd.DataFrame()
32
 
33
- # Polygon oluştur
34
  polygon = Polygon(filter_points.points)
35
-
36
- # İçerde kalanları bul
37
  mask = df[[x_col, y_col]].apply(
38
  lambda row: polygon.contains(Point(row[x_col], row[y_col])),
39
  axis=1
40
  )
41
 
42
- # Sonuçları döndürmeden önce noktaları sıfırla
43
  filter_points.points = []
44
  return df[mask]
45
 
46
  with gr.Blocks() as demo:
47
- gr.Markdown("## 🎯 Tam Çalışan Veri Seçim Uygulaması")
48
 
49
  df_state = gr.State()
50
 
@@ -54,20 +49,13 @@ with gr.Blocks() as demo:
54
  y_col = gr.Dropdown(label="3. Y Sütunu Seç")
55
 
56
  plot = gr.ScatterPlot(
57
- label="4. Noktaları Seçmek İçin Polygon Çiz",
58
- x_title="X Ekseni",
59
- y_title="Y Ekseni",
60
  show_label=True,
61
  interactive=True
62
  )
63
 
64
- results = gr.DataFrame(
65
- label="Seçilen Veriler",
66
- headers=["Tüm Sütunlar Gözükecek"],
67
- max_rows=20
68
- )
69
 
70
- # CSV yükleme
71
  csv_upload.upload(
72
  load_csv,
73
  inputs=csv_upload,
@@ -78,7 +66,6 @@ with gr.Blocks() as demo:
78
  outputs=[x_col, y_col]
79
  )
80
 
81
- # Plot güncelleme
82
  x_col.change(
83
  create_plot,
84
  inputs=[df_state, x_col, y_col],
@@ -90,7 +77,6 @@ with gr.Blocks() as demo:
90
  outputs=plot
91
  )
92
 
93
- # Polygon seçimi
94
  plot.select(
95
  filter_points,
96
  inputs=[df_state, x_col, y_col],
 
1
  import gradio as gr
2
  import pandas as pd
 
3
  from shapely.geometry import Point, Polygon
4
 
5
  def load_csv(file):
 
15
  "x": df[x_col].tolist(),
16
  "y": df[y_col].tolist(),
17
  "color": "blue",
18
+ "tooltip": df.columns.tolist(),
19
+ "x_title": x_col,
20
+ "y_title": y_col
21
  }
22
 
23
  def filter_points(event: gr.SelectData, df, x_col, y_col):
24
  if not hasattr(filter_points, "points"):
25
  filter_points.points = []
26
 
 
27
  filter_points.points.append((event.x, event.y))
28
 
 
29
  if len(filter_points.points) < 3:
30
  return pd.DataFrame()
31
 
 
32
  polygon = Polygon(filter_points.points)
 
 
33
  mask = df[[x_col, y_col]].apply(
34
  lambda row: polygon.contains(Point(row[x_col], row[y_col])),
35
  axis=1
36
  )
37
 
 
38
  filter_points.points = []
39
  return df[mask]
40
 
41
  with gr.Blocks() as demo:
42
+ gr.Markdown("## 🎯 Çalışan Versiyon")
43
 
44
  df_state = gr.State()
45
 
 
49
  y_col = gr.Dropdown(label="3. Y Sütunu Seç")
50
 
51
  plot = gr.ScatterPlot(
52
+ label="4. Lasso Tool ile Alan Seç",
 
 
53
  show_label=True,
54
  interactive=True
55
  )
56
 
57
+ results = gr.DataFrame(label="Seçilen Veriler")
 
 
 
 
58
 
 
59
  csv_upload.upload(
60
  load_csv,
61
  inputs=csv_upload,
 
66
  outputs=[x_col, y_col]
67
  )
68
 
 
69
  x_col.change(
70
  create_plot,
71
  inputs=[df_state, x_col, y_col],
 
77
  outputs=plot
78
  )
79
 
 
80
  plot.select(
81
  filter_points,
82
  inputs=[df_state, x_col, y_col],