FILALIHicham commited on
Commit
13fd451
·
1 Parent(s): f3a0d02

Implement submit handler to show the missing fields

Browse files
Files changed (1) hide show
  1. app.py +12 -5
app.py CHANGED
@@ -16,6 +16,17 @@ from ui.form_components import (
16
  # Initialize Hugging Face
17
  init_huggingface()
18
 
 
 
 
 
 
 
 
 
 
 
 
19
  # Create Gradio interface
20
  with gr.Blocks() as demo:
21
  gr.Markdown("## Data Collection Form")
@@ -40,7 +51,7 @@ with gr.Blocks() as demo:
40
 
41
  # Event Handlers
42
  submit_button.click(
43
- generate_json,
44
  inputs=[
45
  *header_components,
46
  *task_components,
@@ -53,10 +64,6 @@ with gr.Blocks() as demo:
53
  *hash_components
54
  ],
55
  outputs=[output, file_output, json_output]
56
- ).then(
57
- update_dataset,
58
- inputs=json_output,
59
- outputs=output
60
  )
61
 
62
  if __name__ == "__main__":
 
16
  # Initialize Hugging Face
17
  init_huggingface()
18
 
19
+ def handle_submit(*inputs):
20
+ message, file_output, json_output = generate_json(*inputs)
21
+
22
+ # Check if the message indicates validation failure
23
+ if message.startswith("The following fields are required"):
24
+ return message, file_output, json_output
25
+
26
+ # If validation passed, proceed to update_dataset
27
+ update_output = update_dataset(json_output)
28
+ return update_output, file_output, json_output
29
+
30
  # Create Gradio interface
31
  with gr.Blocks() as demo:
32
  gr.Markdown("## Data Collection Form")
 
51
 
52
  # Event Handlers
53
  submit_button.click(
54
+ handle_submit,
55
  inputs=[
56
  *header_components,
57
  *task_components,
 
64
  *hash_components
65
  ],
66
  outputs=[output, file_output, json_output]
 
 
 
 
67
  )
68
 
69
  if __name__ == "__main__":