Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -17,7 +17,7 @@ def get_choices(df, column):
|
|
| 17 |
vals = sorted(df[column].dropna().unique().tolist())
|
| 18 |
return ["All"] + [str(v) for v in vals]
|
| 19 |
|
| 20 |
-
def filter_data(platform, behavior_category, confidence):
|
| 21 |
df = load_data()
|
| 22 |
if platform != "All":
|
| 23 |
df = df[df["platform"].astype(str) == platform]
|
|
@@ -25,6 +25,14 @@ def filter_data(platform, behavior_category, confidence):
|
|
| 25 |
df = df[df["behavior_category"].astype(str) == behavior_category]
|
| 26 |
if confidence != "All":
|
| 27 |
df = df[df["interpretive_confidence"].astype(str) == confidence]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
return df
|
| 29 |
|
| 30 |
def submit_observation(
|
|
@@ -86,17 +94,30 @@ with gr.Blocks(title="Coherence Gap Explorer") as demo:
|
|
| 86 |
value="All", label="Interpretive Confidence"
|
| 87 |
)
|
| 88 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
table = gr.Dataframe(
|
| 90 |
value=initial_df, label="Observations",
|
| 91 |
interactive=False, wrap=True
|
| 92 |
)
|
| 93 |
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
|
| 101 |
with gr.Tab("Submit Observation"):
|
| 102 |
gr.Markdown("### Add a New Observation")
|
|
|
|
| 17 |
vals = sorted(df[column].dropna().unique().tolist())
|
| 18 |
return ["All"] + [str(v) for v in vals]
|
| 19 |
|
| 20 |
+
def filter_data(platform, behavior_category, confidence, search_term):
|
| 21 |
df = load_data()
|
| 22 |
if platform != "All":
|
| 23 |
df = df[df["platform"].astype(str) == platform]
|
|
|
|
| 25 |
df = df[df["behavior_category"].astype(str) == behavior_category]
|
| 26 |
if confidence != "All":
|
| 27 |
df = df[df["interpretive_confidence"].astype(str) == confidence]
|
| 28 |
+
if search_term.strip():
|
| 29 |
+
mask = df.apply(
|
| 30 |
+
lambda row: row.astype(str).str.contains(
|
| 31 |
+
search_term.strip(), case=False, na=False
|
| 32 |
+
).any(),
|
| 33 |
+
axis=1
|
| 34 |
+
)
|
| 35 |
+
df = df[mask]
|
| 36 |
return df
|
| 37 |
|
| 38 |
def submit_observation(
|
|
|
|
| 94 |
value="All", label="Interpretive Confidence"
|
| 95 |
)
|
| 96 |
|
| 97 |
+
search_box = gr.Textbox(
|
| 98 |
+
label="Search",
|
| 99 |
+
placeholder="Search across all columns...",
|
| 100 |
+
lines=1
|
| 101 |
+
)
|
| 102 |
+
|
| 103 |
+
result_count = gr.Markdown("")
|
| 104 |
+
|
| 105 |
table = gr.Dataframe(
|
| 106 |
value=initial_df, label="Observations",
|
| 107 |
interactive=False, wrap=True
|
| 108 |
)
|
| 109 |
|
| 110 |
+
def update(platform, behavior_category, confidence, search_term):
|
| 111 |
+
df = filter_data(platform, behavior_category, confidence, search_term)
|
| 112 |
+
count = f"*Showing {len(df)} of {len(load_data())} observations*"
|
| 113 |
+
return df, count
|
| 114 |
+
|
| 115 |
+
inputs = [platform_dd, category_dd, confidence_dd, search_box]
|
| 116 |
+
|
| 117 |
+
for component in [platform_dd, category_dd, confidence_dd]:
|
| 118 |
+
component.change(fn=update, inputs=inputs, outputs=[table, result_count])
|
| 119 |
+
|
| 120 |
+
search_box.change(fn=update, inputs=inputs, outputs=[table, result_count])
|
| 121 |
|
| 122 |
with gr.Tab("Submit Observation"):
|
| 123 |
gr.Markdown("### Add a New Observation")
|