Spaces:
Running
Running
more fixes
Browse files
app.py
CHANGED
@@ -12,7 +12,6 @@ source_finders = []
|
|
12 |
questions_dict = {}
|
13 |
source_finders_dict = {}
|
14 |
question_options = []
|
15 |
-
baseline_rankers = []
|
16 |
baseline_rankers_dict = {}
|
17 |
baseline_ranker_options = []
|
18 |
run_ids = []
|
@@ -26,43 +25,44 @@ run_id_dropdown = None
|
|
26 |
|
27 |
# Initialize data in a single async function
|
28 |
async def initialize_data():
|
29 |
-
global questions, source_finders, questions_dict, source_finders_dict, question_options, finder_options, finder_labels,
|
30 |
|
31 |
questions = await get_questions()
|
32 |
source_finders = await get_source_finders()
|
33 |
|
34 |
baseline_rankers = await get_baseline_rankers()
|
35 |
-
baseline_rankers_dict = {f["
|
36 |
|
37 |
# Convert to dictionaries for easier lookup
|
38 |
-
questions_dict = {q["
|
39 |
-
|
|
|
40 |
|
41 |
# Create formatted options for dropdowns
|
42 |
-
question_options = [
|
43 |
-
finder_options = [
|
44 |
finder_labels = {str(f["id"]): f["name"] for f in source_finders}
|
45 |
-
baseline_ranker_options = [
|
46 |
-
baseline_ranker_labels = {str(f["id"]): f["name"] for f in source_finders}
|
47 |
|
48 |
|
49 |
-
|
|
|
50 |
global previous_run_id
|
51 |
-
if evt
|
52 |
-
if run_id == previous_run_id:
|
53 |
return gr.skip(), gr.skip(), gr.skip(), gr.skip()
|
54 |
-
|
55 |
previous_run_id = run_id
|
56 |
-
return asyncio.run(update_sources_list_async(question_option, source_finder_id,
|
57 |
|
58 |
|
59 |
# Main function to handle UI interactions
|
60 |
-
async def update_sources_list_async(question_option,
|
61 |
if not question_option:
|
62 |
return gr.skip(), gr.skip(), gr.skip(), "No question selected"
|
63 |
|
64 |
# Extract question ID from selection
|
65 |
-
question_id =
|
66 |
|
67 |
available_run_ids = await get_run_ids(question_id)
|
68 |
run_id_options = [str(r_id) for r_id in available_run_ids]
|
@@ -70,10 +70,15 @@ async def update_sources_list_async(question_option, source_finder_id, baseline_
|
|
70 |
run_id = run_id_options[0]
|
71 |
|
72 |
run_id_int = int(run_id)
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
|
|
|
|
|
|
|
|
|
|
77 |
|
78 |
source_runs = None
|
79 |
stats = None
|
@@ -144,31 +149,6 @@ async def main():
|
|
144 |
interactive=True,
|
145 |
elem_id="run_id_dropdown"
|
146 |
)
|
147 |
-
|
148 |
-
result_text = gr.Markdown("Select a question to view source runs")
|
149 |
-
gr.Markdown("# Source Run Statistics")
|
150 |
-
statistics_table = gr.DataFrame(
|
151 |
-
headers=["num_high_ranked_baseline_sources",
|
152 |
-
"num_high_ranked_found_sources",
|
153 |
-
"overlap_count",
|
154 |
-
"overlap_percentage",
|
155 |
-
"high_ranked_overlap_count",
|
156 |
-
"high_ranked_overlap_percentage"
|
157 |
-
],
|
158 |
-
interactive=False,
|
159 |
-
)
|
160 |
-
gr.Markdown("# Sources Found")
|
161 |
-
results_table = gr.DataFrame(
|
162 |
-
headers=['Source Finder', 'Run ID', 'Sugya ID', 'Tractate', 'Folio', 'Rank', 'Reason'],
|
163 |
-
interactive=False
|
164 |
-
)
|
165 |
-
|
166 |
-
# download_button = gr.DownloadButton(
|
167 |
-
# label="Download Results as CSV",
|
168 |
-
# interactive=True,
|
169 |
-
# visible=True
|
170 |
-
# )
|
171 |
-
|
172 |
with gr.Column(scale=1):
|
173 |
# Sidebar area
|
174 |
gr.Markdown("### About")
|
@@ -179,12 +159,37 @@ async def main():
|
|
179 |
gr.Markdown(f"Total Questions: {len(questions)}")
|
180 |
gr.Markdown(f"Source Finders: {len(source_finders)}")
|
181 |
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
188 |
|
189 |
# Set up event handlers
|
190 |
question_dropdown.change(
|
|
|
12 |
questions_dict = {}
|
13 |
source_finders_dict = {}
|
14 |
question_options = []
|
|
|
15 |
baseline_rankers_dict = {}
|
16 |
baseline_ranker_options = []
|
17 |
run_ids = []
|
|
|
25 |
|
26 |
# Initialize data in a single async function
|
27 |
async def initialize_data():
|
28 |
+
global questions, source_finders, questions_dict, source_finders_dict, question_options, finder_options, finder_labels, baseline_rankers_dict, source_finders_dict, baseline_ranker_options
|
29 |
|
30 |
questions = await get_questions()
|
31 |
source_finders = await get_source_finders()
|
32 |
|
33 |
baseline_rankers = await get_baseline_rankers()
|
34 |
+
baseline_rankers_dict = {f["name"]: f["id"] for f in baseline_rankers}
|
35 |
|
36 |
# Convert to dictionaries for easier lookup
|
37 |
+
questions_dict = {q["text"]: q["id"] for q in questions}
|
38 |
+
baseline_rankers_dict = {f["name"]: f["id"] for f in baseline_rankers}
|
39 |
+
source_finders_dict = {f["name"]: f["id"] for f in source_finders}
|
40 |
|
41 |
# Create formatted options for dropdowns
|
42 |
+
question_options = [q['text'] for q in questions]
|
43 |
+
finder_options = [s["name"] for s in source_finders]
|
44 |
finder_labels = {str(f["id"]): f["name"] for f in source_finders}
|
45 |
+
baseline_ranker_options = [b["name"] for b in baseline_rankers]
|
|
|
46 |
|
47 |
|
48 |
+
|
49 |
+
def update_sources_list(question_option, source_finder_id, run_id: str, baseline_ranker_id: str, evt: gr.EventData = None):
|
50 |
global previous_run_id
|
51 |
+
if evt.target.elem_id == "run_id_dropdown":
|
52 |
+
if type(run_id) == list or run_id == previous_run_id:
|
53 |
return gr.skip(), gr.skip(), gr.skip(), gr.skip()
|
54 |
+
|
55 |
previous_run_id = run_id
|
56 |
+
return asyncio.run(update_sources_list_async(question_option, source_finder_id, run_id, baseline_ranker_id))
|
57 |
|
58 |
|
59 |
# Main function to handle UI interactions
|
60 |
+
async def update_sources_list_async(question_option, source_finder_name, run_id:str, baseline_ranker_name: str):
|
61 |
if not question_option:
|
62 |
return gr.skip(), gr.skip(), gr.skip(), "No question selected"
|
63 |
|
64 |
# Extract question ID from selection
|
65 |
+
question_id = questions_dict.get(question_option)
|
66 |
|
67 |
available_run_ids = await get_run_ids(question_id)
|
68 |
run_id_options = [str(r_id) for r_id in available_run_ids]
|
|
|
70 |
run_id = run_id_options[0]
|
71 |
|
72 |
run_id_int = int(run_id)
|
73 |
+
if len(source_finder_name):
|
74 |
+
finder_id_int = source_finders_dict.get(source_finder_name)
|
75 |
+
else:
|
76 |
+
finder_id_int = None
|
77 |
+
|
78 |
+
if type(baseline_ranker_name) == list:
|
79 |
+
baseline_ranker_name = baseline_ranker_name[0]
|
80 |
+
|
81 |
+
baseline_ranker_id_int = 1 if len(baseline_ranker_name) == 0 else baseline_rankers_dict.get(baseline_ranker_name)
|
82 |
|
83 |
source_runs = None
|
84 |
stats = None
|
|
|
149 |
interactive=True,
|
150 |
elem_id="run_id_dropdown"
|
151 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
152 |
with gr.Column(scale=1):
|
153 |
# Sidebar area
|
154 |
gr.Markdown("### About")
|
|
|
159 |
gr.Markdown(f"Total Questions: {len(questions)}")
|
160 |
gr.Markdown(f"Source Finders: {len(source_finders)}")
|
161 |
|
162 |
+
|
163 |
+
with gr.Row():
|
164 |
+
result_text = gr.Markdown("Select a question to view source runs")
|
165 |
+
with gr.Row():
|
166 |
+
gr.Markdown("# Source Run Statistics")
|
167 |
+
with gr.Row():
|
168 |
+
statistics_table = gr.DataFrame(
|
169 |
+
headers=["num_high_ranked_baseline_sources",
|
170 |
+
"num_high_ranked_found_sources",
|
171 |
+
"overlap_count",
|
172 |
+
"overlap_percentage",
|
173 |
+
"high_ranked_overlap_count",
|
174 |
+
"high_ranked_overlap_percentage"
|
175 |
+
],
|
176 |
+
interactive=False,
|
177 |
+
)
|
178 |
+
with gr.Row():
|
179 |
+
gr.Markdown("# Sources Found")
|
180 |
+
with gr.Row():
|
181 |
+
results_table = gr.DataFrame(
|
182 |
+
headers=['Source Finder', 'Run ID', 'Sugya ID', 'Tractate', 'Folio', 'Rank', 'Reason'],
|
183 |
+
interactive=False
|
184 |
+
)
|
185 |
+
|
186 |
+
# download_button = gr.DownloadButton(
|
187 |
+
# label="Download Results as CSV",
|
188 |
+
# interactive=True,
|
189 |
+
# visible=True
|
190 |
+
# )
|
191 |
+
|
192 |
+
|
193 |
|
194 |
# Set up event handlers
|
195 |
question_dropdown.change(
|