Spaces:
Paused
Paused
backup
Browse files
app.py
CHANGED
|
@@ -94,7 +94,7 @@ def load_question_data(question_id):
|
|
| 94 |
Returns a tuple of all form fields
|
| 95 |
"""
|
| 96 |
if not question_id:
|
| 97 |
-
return [None] * 26 #
|
| 98 |
|
| 99 |
# Extract the ID part before the colon from the dropdown selection
|
| 100 |
question_id = (
|
|
@@ -104,7 +104,7 @@ def load_question_data(question_id):
|
|
| 104 |
json_path = os.path.join("./data", question_id, "question.json")
|
| 105 |
if not os.path.exists(json_path):
|
| 106 |
print(f"Question file not found: {json_path}")
|
| 107 |
-
return [None] * 26
|
| 108 |
|
| 109 |
try:
|
| 110 |
with open(json_path, "r", encoding="utf-8") as f:
|
|
@@ -158,10 +158,11 @@ def load_question_data(question_id):
|
|
| 158 |
load_image(question_images[3] if len(question_images) > 3 else None),
|
| 159 |
load_image(rationale_images[0] if rationale_images else None),
|
| 160 |
load_image(rationale_images[1] if len(rationale_images) > 1 else None),
|
|
|
|
| 161 |
]
|
| 162 |
except Exception as e:
|
| 163 |
print(f"Error loading question {question_id}: {str(e)}")
|
| 164 |
-
return [None] * 26
|
| 165 |
|
| 166 |
|
| 167 |
def generate_json_files(
|
|
@@ -443,6 +444,8 @@ def generate_json_files(
|
|
| 443 |
# Build the Gradio app
|
| 444 |
with gr.Blocks() as demo:
|
| 445 |
gr.Markdown("# Dataset Builder")
|
|
|
|
|
|
|
| 446 |
|
| 447 |
with gr.Accordion("Instructions", open=True):
|
| 448 |
gr.HTML(
|
|
@@ -699,6 +702,7 @@ with gr.Blocks() as demo:
|
|
| 699 |
image4,
|
| 700 |
rationale_image1,
|
| 701 |
rationale_image2,
|
|
|
|
| 702 |
],
|
| 703 |
)
|
| 704 |
|
|
@@ -730,7 +734,7 @@ with gr.Blocks() as demo:
|
|
| 730 |
i4,
|
| 731 |
ri1,
|
| 732 |
ri2,
|
| 733 |
-
|
| 734 |
):
|
| 735 |
# Validation code remains the same
|
| 736 |
missing_fields = []
|
|
@@ -766,10 +770,8 @@ with gr.Blocks() as demo:
|
|
| 766 |
choices=load_existing_questions()
|
| 767 |
)
|
| 768 |
|
| 769 |
-
#
|
| 770 |
-
existing_id =
|
| 771 |
-
selected_question_id.split(":")[0].strip() if selected_question_id else None
|
| 772 |
-
)
|
| 773 |
|
| 774 |
results = generate_json_files(
|
| 775 |
nm,
|
|
@@ -810,7 +812,7 @@ with gr.Blocks() as demo:
|
|
| 810 |
choices=load_existing_questions()
|
| 811 |
)
|
| 812 |
|
| 813 |
-
# Update submit button click handler to
|
| 814 |
submit_button.click(
|
| 815 |
fn=validate_and_generate,
|
| 816 |
inputs=[
|
|
@@ -840,12 +842,12 @@ with gr.Blocks() as demo:
|
|
| 840 |
image4,
|
| 841 |
rationale_image1,
|
| 842 |
rationale_image2,
|
| 843 |
-
|
| 844 |
],
|
| 845 |
-
outputs=[submit_button, existing_questions],
|
| 846 |
)
|
| 847 |
|
| 848 |
-
#
|
| 849 |
def clear_form_fields(name, email, inst, openreview, authorship, *args):
|
| 850 |
outputs = [
|
| 851 |
name, # Preserve name
|
|
@@ -876,11 +878,13 @@ with gr.Blocks() as demo:
|
|
| 876 |
None, # Clear rationale image2
|
| 877 |
None, # Clear output file urls
|
| 878 |
gr.Button(interactive=True), # Re-enable submit button
|
| 879 |
-
gr.update(
|
|
|
|
| 880 |
]
|
| 881 |
gr.Info("Form cleared! Ready for new submission 🔄")
|
| 882 |
return outputs
|
| 883 |
|
|
|
|
| 884 |
clear_button.click(
|
| 885 |
fn=clear_form_fields,
|
| 886 |
inputs=[
|
|
@@ -920,6 +924,7 @@ with gr.Blocks() as demo:
|
|
| 920 |
output_file_urls,
|
| 921 |
submit_button,
|
| 922 |
existing_questions,
|
|
|
|
| 923 |
],
|
| 924 |
)
|
| 925 |
|
|
|
|
| 94 |
Returns a tuple of all form fields
|
| 95 |
"""
|
| 96 |
if not question_id:
|
| 97 |
+
return [None] * 26 + [None] # Changed from gr.State(value=None) to just None
|
| 98 |
|
| 99 |
# Extract the ID part before the colon from the dropdown selection
|
| 100 |
question_id = (
|
|
|
|
| 104 |
json_path = os.path.join("./data", question_id, "question.json")
|
| 105 |
if not os.path.exists(json_path):
|
| 106 |
print(f"Question file not found: {json_path}")
|
| 107 |
+
return [None] * 26 + [None]
|
| 108 |
|
| 109 |
try:
|
| 110 |
with open(json_path, "r", encoding="utf-8") as f:
|
|
|
|
| 158 |
load_image(question_images[3] if len(question_images) > 3 else None),
|
| 159 |
load_image(rationale_images[0] if rationale_images else None),
|
| 160 |
load_image(rationale_images[1] if len(rationale_images) > 1 else None),
|
| 161 |
+
question_id, # Changed from gr.State(value=question_id) to just question_id
|
| 162 |
]
|
| 163 |
except Exception as e:
|
| 164 |
print(f"Error loading question {question_id}: {str(e)}")
|
| 165 |
+
return [None] * 26 + [None]
|
| 166 |
|
| 167 |
|
| 168 |
def generate_json_files(
|
|
|
|
| 444 |
# Build the Gradio app
|
| 445 |
with gr.Blocks() as demo:
|
| 446 |
gr.Markdown("# Dataset Builder")
|
| 447 |
+
# Add a global state variable at the top level
|
| 448 |
+
loaded_question_id = gr.State()
|
| 449 |
|
| 450 |
with gr.Accordion("Instructions", open=True):
|
| 451 |
gr.HTML(
|
|
|
|
| 702 |
image4,
|
| 703 |
rationale_image1,
|
| 704 |
rationale_image2,
|
| 705 |
+
loaded_question_id,
|
| 706 |
],
|
| 707 |
)
|
| 708 |
|
|
|
|
| 734 |
i4,
|
| 735 |
ri1,
|
| 736 |
ri2,
|
| 737 |
+
stored_question_id, # Add this parameter
|
| 738 |
):
|
| 739 |
# Validation code remains the same
|
| 740 |
missing_fields = []
|
|
|
|
| 770 |
choices=load_existing_questions()
|
| 771 |
)
|
| 772 |
|
| 773 |
+
# Use the stored ID instead of extracting from dropdown
|
| 774 |
+
existing_id = stored_question_id if stored_question_id else None
|
|
|
|
|
|
|
| 775 |
|
| 776 |
results = generate_json_files(
|
| 777 |
nm,
|
|
|
|
| 812 |
choices=load_existing_questions()
|
| 813 |
)
|
| 814 |
|
| 815 |
+
# Update submit button click handler to match inputs/outputs correctly
|
| 816 |
submit_button.click(
|
| 817 |
fn=validate_and_generate,
|
| 818 |
inputs=[
|
|
|
|
| 842 |
image4,
|
| 843 |
rationale_image1,
|
| 844 |
rationale_image2,
|
| 845 |
+
loaded_question_id,
|
| 846 |
],
|
| 847 |
+
outputs=[submit_button, existing_questions],
|
| 848 |
)
|
| 849 |
|
| 850 |
+
# Fix the clear_form_fields function
|
| 851 |
def clear_form_fields(name, email, inst, openreview, authorship, *args):
|
| 852 |
outputs = [
|
| 853 |
name, # Preserve name
|
|
|
|
| 878 |
None, # Clear rationale image2
|
| 879 |
None, # Clear output file urls
|
| 880 |
gr.Button(interactive=True), # Re-enable submit button
|
| 881 |
+
gr.update(choices=load_existing_questions()), # Update dropdown
|
| 882 |
+
None, # Changed from gr.State(value=None) to just None
|
| 883 |
]
|
| 884 |
gr.Info("Form cleared! Ready for new submission 🔄")
|
| 885 |
return outputs
|
| 886 |
|
| 887 |
+
# Update the clear button click handler
|
| 888 |
clear_button.click(
|
| 889 |
fn=clear_form_fields,
|
| 890 |
inputs=[
|
|
|
|
| 924 |
output_file_urls,
|
| 925 |
submit_button,
|
| 926 |
existing_questions,
|
| 927 |
+
loaded_question_id,
|
| 928 |
],
|
| 929 |
)
|
| 930 |
|