Update app.py
Browse files
app.py
CHANGED
|
@@ -1,23 +1,21 @@
|
|
| 1 |
-
|
| 2 |
import pandas as pd
|
| 3 |
import gradio as gr
|
| 4 |
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
def
|
| 7 |
-
if file_obj is None:
|
| 8 |
-
return None, "Upload a judged CSV to begin."
|
| 9 |
try:
|
| 10 |
-
df = pd.read_csv(
|
| 11 |
return df, ""
|
| 12 |
except Exception as e:
|
| 13 |
-
return None, f"Failed to read CSV: {e}"
|
| 14 |
|
| 15 |
|
| 16 |
-
def filter_rows(
|
| 17 |
-
df
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
if df is None or df.empty:
|
| 21 |
return "No data in CSV.", "", None
|
| 22 |
|
| 23 |
# Expected columns from judged-fast-accurate CSV
|
|
@@ -92,7 +90,8 @@ def filter_rows(file_obj, mode, similar, text_filter, max_rows):
|
|
| 92 |
with gr.Blocks() as demo:
|
| 93 |
gr.Markdown("# OCR Judge Viewer")
|
| 94 |
with gr.Row():
|
| 95 |
-
|
|
|
|
| 96 |
mode = gr.Dropdown(["both", "fast", "accurate"], value="both", label="Mode")
|
| 97 |
similar = gr.Dropdown(["all", "true", "false"], value="all", label="similar flag")
|
| 98 |
text_filter = gr.Textbox(label="Search text", placeholder="search in truth/reasons")
|
|
@@ -100,12 +99,15 @@ with gr.Blocks() as demo:
|
|
| 100 |
err_box = gr.Markdown()
|
| 101 |
summary_box = gr.Markdown()
|
| 102 |
table = gr.Dataframe(wrap=True)
|
|
|
|
| 103 |
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
|
|
|
|
|
|
| 109 |
|
| 110 |
if __name__ == "__main__":
|
| 111 |
-
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
|
|
|
| 1 |
import pandas as pd
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
+
CSV_PATH = "/judged-fast-accurate-downsampled.csv"
|
| 5 |
+
|
| 6 |
|
| 7 |
+
def load_csv_from_path(path: str):
|
|
|
|
|
|
|
| 8 |
try:
|
| 9 |
+
df = pd.read_csv(path)
|
| 10 |
return df, ""
|
| 11 |
except Exception as e:
|
| 12 |
+
return None, f"Failed to read CSV at {path}: {e}"
|
| 13 |
|
| 14 |
|
| 15 |
+
def filter_rows(df, mode, similar, text_filter, max_rows):
|
| 16 |
+
if df is None:
|
| 17 |
+
return "No data loaded. Click Reload.", "", None
|
| 18 |
+
if df.empty:
|
|
|
|
| 19 |
return "No data in CSV.", "", None
|
| 20 |
|
| 21 |
# Expected columns from judged-fast-accurate CSV
|
|
|
|
| 90 |
with gr.Blocks() as demo:
|
| 91 |
gr.Markdown("# OCR Judge Viewer")
|
| 92 |
with gr.Row():
|
| 93 |
+
path_in = gr.Textbox(value=CSV_PATH, label="CSV path", interactive=True)
|
| 94 |
+
reload_btn = gr.Button("Reload")
|
| 95 |
mode = gr.Dropdown(["both", "fast", "accurate"], value="both", label="Mode")
|
| 96 |
similar = gr.Dropdown(["all", "true", "false"], value="all", label="similar flag")
|
| 97 |
text_filter = gr.Textbox(label="Search text", placeholder="search in truth/reasons")
|
|
|
|
| 99 |
err_box = gr.Markdown()
|
| 100 |
summary_box = gr.Markdown()
|
| 101 |
table = gr.Dataframe(wrap=True)
|
| 102 |
+
data_state = gr.State(None)
|
| 103 |
|
| 104 |
+
reload_btn.click(load_csv_from_path, [path_in], [data_state, err_box]).then(
|
| 105 |
+
filter_rows, [data_state, mode, similar, text_filter, max_rows], [err_box, summary_box, table]
|
| 106 |
+
)
|
| 107 |
+
mode.change(filter_rows, [data_state, mode, similar, text_filter, max_rows], [err_box, summary_box, table])
|
| 108 |
+
similar.change(filter_rows, [data_state, mode, similar, text_filter, max_rows], [err_box, summary_box, table])
|
| 109 |
+
text_filter.change(filter_rows, [data_state, mode, similar, text_filter, max_rows], [err_box, summary_box, table])
|
| 110 |
+
max_rows.change(filter_rows, [data_state, mode, similar, text_filter, max_rows], [err_box, summary_box, table])
|
| 111 |
|
| 112 |
if __name__ == "__main__":
|
| 113 |
+
demo.launch(server_name="0.0.0.0", server_port=7860, ssr_mode=False)
|