Spaces:
Running on Zero
Running on Zero
Upload 41 files
Browse files- __pycache__/app.cpython-310.pyc +0 -0
- app.py +13 -17
__pycache__/app.cpython-310.pyc
CHANGED
|
Binary files a/__pycache__/app.cpython-310.pyc and b/__pycache__/app.cpython-310.pyc differ
|
|
|
app.py
CHANGED
|
@@ -96,7 +96,8 @@ def click_gaze(image, points, weight, event: gr.SelectData):
|
|
| 96 |
def prepare_csv(file):
|
| 97 |
"""Read a CSV and expose its columns for explicit user mapping."""
|
| 98 |
hidden = (None, gr.update(visible=False), gr.update(choices=[], value=None),
|
| 99 |
-
gr.update(choices=[], value=None), gr.update(choices=[], value=
|
|
|
|
| 100 |
gr.update(visible=False))
|
| 101 |
if file is None:
|
| 102 |
return hidden
|
|
@@ -107,10 +108,12 @@ def prepare_csv(file):
|
|
| 107 |
raise ValueError("CSV contains no rows.")
|
| 108 |
columns = [str(column) for column in frame.columns]
|
| 109 |
lower = {column.lower().strip(): column for column in columns}
|
|
|
|
| 110 |
x_guess = lower.get("x") or lower.get("gaze_x") or lower.get("fix_x") or columns[0]
|
| 111 |
y_guess = lower.get("y") or lower.get("gaze_y") or lower.get("fix_y") or columns[min(1, len(columns) - 1)]
|
| 112 |
duration_guess = lower.get("duration") or lower.get("weight") or lower.get("fixation_duration") or NO_DURATION
|
| 113 |
return (frame.to_json(orient="split"), gr.update(visible=True),
|
|
|
|
| 114 |
gr.update(choices=columns, value=x_guess),
|
| 115 |
gr.update(choices=columns, value=y_guess),
|
| 116 |
gr.update(choices=[NO_DURATION] + columns, value=duration_guess),
|
|
@@ -120,25 +123,17 @@ def prepare_csv(file):
|
|
| 120 |
return hidden
|
| 121 |
|
| 122 |
|
| 123 |
-
def apply_csv(frame_json, x_col, y_col, duration_col, image, image_name):
|
| 124 |
if image is None:
|
| 125 |
gr.Warning("Upload an image before applying gaze CSV data.")
|
| 126 |
return gr.update(), gr.update()
|
| 127 |
-
if not frame_json or not x_col or not y_col:
|
| 128 |
-
gr.Warning("Select the X and Y columns first.")
|
| 129 |
return gr.update(), gr.update()
|
| 130 |
try:
|
| 131 |
frame = pd.read_json(frame_json, orient="split")
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
# to importing every row: this file can contain gaze for many images.
|
| 135 |
-
id_col = next(
|
| 136 |
-
(column for column in frame.columns
|
| 137 |
-
if str(column).lstrip("\ufeff").strip().casefold() == "id"),
|
| 138 |
-
None,
|
| 139 |
-
)
|
| 140 |
-
if id_col is None:
|
| 141 |
-
raise ValueError('CSV must contain an "id" column to import gaze for the selected image.')
|
| 142 |
if not image_name:
|
| 143 |
raise ValueError("The uploaded image name is unavailable for matching the CSV id column.")
|
| 144 |
image_path = Path(image_name)
|
|
@@ -240,9 +235,10 @@ with gr.Blocks(title="GazeCorrect") as demo:
|
|
| 240 |
weight = gr.Slider(.1, 1, value=1, step=.1, label="Next click weight")
|
| 241 |
clear_button = gr.Button("Clear gaze", variant="secondary")
|
| 242 |
with gr.Accordion("Import gaze CSV", open=False):
|
| 243 |
-
gr.Markdown("Upload a CSV
|
| 244 |
csv_file = gr.File(label="Choose CSV", file_types=[".csv", ".tsv", ".txt"])
|
| 245 |
with gr.Row(visible=False) as csv_mapping:
|
|
|
|
| 246 |
x_column = gr.Dropdown(label="X column")
|
| 247 |
y_column = gr.Dropdown(label="Y column")
|
| 248 |
duration_column = gr.Dropdown(label="Duration / weight (optional)")
|
|
@@ -264,8 +260,8 @@ with gr.Blocks(title="GazeCorrect") as demo:
|
|
| 264 |
upload.upload(load_image, upload, [image_state, points_state, image_name_state, panel])
|
| 265 |
panel.select(click_gaze, [image_state, points_state, weight], [points_state, panel])
|
| 266 |
clear_button.click(clear_gaze, image_state, [points_state, panel])
|
| 267 |
-
csv_file.upload(prepare_csv, csv_file, [csv_state, csv_mapping, x_column, y_column, duration_column, apply_csv_button])
|
| 268 |
-
apply_csv_button.click(apply_csv, [csv_state, x_column, y_column, duration_column, image_state, image_name_state], [points_state, panel])
|
| 269 |
button.click(generate, [image_state, points_state, description, sigma, degree, feather, strength, steps, seed], [gaze_out, noise_out, corrected_out, status])
|
| 270 |
|
| 271 |
demo.queue().launch(show_error=True)
|
|
|
|
| 96 |
def prepare_csv(file):
|
| 97 |
"""Read a CSV and expose its columns for explicit user mapping."""
|
| 98 |
hidden = (None, gr.update(visible=False), gr.update(choices=[], value=None),
|
| 99 |
+
gr.update(choices=[], value=None), gr.update(choices=[], value=None),
|
| 100 |
+
gr.update(choices=[], value=NO_DURATION),
|
| 101 |
gr.update(visible=False))
|
| 102 |
if file is None:
|
| 103 |
return hidden
|
|
|
|
| 108 |
raise ValueError("CSV contains no rows.")
|
| 109 |
columns = [str(column) for column in frame.columns]
|
| 110 |
lower = {column.lower().strip(): column for column in columns}
|
| 111 |
+
id_guess = lower.get("id") or lower.get("image_id") or lower.get("image") or lower.get("filename") or columns[0]
|
| 112 |
x_guess = lower.get("x") or lower.get("gaze_x") or lower.get("fix_x") or columns[0]
|
| 113 |
y_guess = lower.get("y") or lower.get("gaze_y") or lower.get("fix_y") or columns[min(1, len(columns) - 1)]
|
| 114 |
duration_guess = lower.get("duration") or lower.get("weight") or lower.get("fixation_duration") or NO_DURATION
|
| 115 |
return (frame.to_json(orient="split"), gr.update(visible=True),
|
| 116 |
+
gr.update(choices=columns, value=id_guess),
|
| 117 |
gr.update(choices=columns, value=x_guess),
|
| 118 |
gr.update(choices=columns, value=y_guess),
|
| 119 |
gr.update(choices=[NO_DURATION] + columns, value=duration_guess),
|
|
|
|
| 123 |
return hidden
|
| 124 |
|
| 125 |
|
| 126 |
+
def apply_csv(frame_json, id_col, x_col, y_col, duration_col, image, image_name):
|
| 127 |
if image is None:
|
| 128 |
gr.Warning("Upload an image before applying gaze CSV data.")
|
| 129 |
return gr.update(), gr.update()
|
| 130 |
+
if not frame_json or not id_col or not x_col or not y_col:
|
| 131 |
+
gr.Warning("Select the ID, X, and Y columns first.")
|
| 132 |
return gr.update(), gr.update()
|
| 133 |
try:
|
| 134 |
frame = pd.read_json(frame_json, orient="split")
|
| 135 |
+
if id_col not in frame.columns:
|
| 136 |
+
raise ValueError(f'ID column "{id_col}" was not found in the CSV.')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
if not image_name:
|
| 138 |
raise ValueError("The uploaded image name is unavailable for matching the CSV id column.")
|
| 139 |
image_path = Path(image_name)
|
|
|
|
| 235 |
weight = gr.Slider(.1, 1, value=1, step=.1, label="Next click weight")
|
| 236 |
clear_button = gr.Button("Clear gaze", variant="secondary")
|
| 237 |
with gr.Accordion("Import gaze CSV", open=False):
|
| 238 |
+
gr.Markdown("Upload a CSV and select its image ID, fixation X/Y, and optional duration/weight columns. Only rows whose selected ID matches the uploaded image filename (or filename without its extension) are imported.")
|
| 239 |
csv_file = gr.File(label="Choose CSV", file_types=[".csv", ".tsv", ".txt"])
|
| 240 |
with gr.Row(visible=False) as csv_mapping:
|
| 241 |
+
id_column = gr.Dropdown(label="Image ID column")
|
| 242 |
x_column = gr.Dropdown(label="X column")
|
| 243 |
y_column = gr.Dropdown(label="Y column")
|
| 244 |
duration_column = gr.Dropdown(label="Duration / weight (optional)")
|
|
|
|
| 260 |
upload.upload(load_image, upload, [image_state, points_state, image_name_state, panel])
|
| 261 |
panel.select(click_gaze, [image_state, points_state, weight], [points_state, panel])
|
| 262 |
clear_button.click(clear_gaze, image_state, [points_state, panel])
|
| 263 |
+
csv_file.upload(prepare_csv, csv_file, [csv_state, csv_mapping, id_column, x_column, y_column, duration_column, apply_csv_button])
|
| 264 |
+
apply_csv_button.click(apply_csv, [csv_state, id_column, x_column, y_column, duration_column, image_state, image_name_state], [points_state, panel])
|
| 265 |
button.click(generate, [image_state, points_state, description, sigma, degree, feather, strength, steps, seed], [gaze_out, noise_out, corrected_out, status])
|
| 266 |
|
| 267 |
demo.queue().launch(show_error=True)
|