rifatramadhani commited on
Commit
b9dd0a0
·
1 Parent(s): e70400c
Files changed (2) hide show
  1. app.py +3 -8
  2. utils/ui_utils.py +15 -18
app.py CHANGED
@@ -50,12 +50,7 @@ with gr.Blocks() as demo:
50
  # Link radio button change to visibility update function
51
  face_input_type.change(
52
  fn=update_input_visibility,
53
- inputs=[
54
- face_input_type,
55
- face_img_upload,
56
- face_url_input,
57
- face_base64_input,
58
- ],
59
  outputs=[face_img_upload, face_url_input, face_base64_input],
60
  queue=False,
61
  )
@@ -103,7 +98,7 @@ with gr.Blocks() as demo:
103
  # Link radio button change to visibility update function
104
  age_input_type.change(
105
  fn=update_input_visibility,
106
- inputs=[age_input_type, age_img_upload, age_url_input, age_base64_input],
107
  outputs=[age_img_upload, age_url_input, age_base64_input],
108
  queue=False,
109
  )
@@ -145,7 +140,7 @@ with gr.Blocks() as demo:
145
  # Link radio button change to visibility update function
146
  obj_input_type.change(
147
  fn=update_input_visibility,
148
- inputs=[obj_input_type, obj_img_upload, obj_url_input, obj_base64_input],
149
  outputs=[obj_img_upload, obj_url_input, obj_base64_input],
150
  queue=False,
151
  )
 
50
  # Link radio button change to visibility update function
51
  face_input_type.change(
52
  fn=update_input_visibility,
53
+ inputs=[face_input_type],
 
 
 
 
 
54
  outputs=[face_img_upload, face_url_input, face_base64_input],
55
  queue=False,
56
  )
 
98
  # Link radio button change to visibility update function
99
  age_input_type.change(
100
  fn=update_input_visibility,
101
+ inputs=[age_input_type],
102
  outputs=[age_img_upload, age_url_input, age_base64_input],
103
  queue=False,
104
  )
 
140
  # Link radio button change to visibility update function
141
  obj_input_type.change(
142
  fn=update_input_visibility,
143
+ inputs=[obj_input_type],
144
  outputs=[obj_img_upload, obj_url_input, obj_base64_input],
145
  queue=False,
146
  )
utils/ui_utils.py CHANGED
@@ -1,40 +1,37 @@
1
  # Utility functions for UI components
2
  import gradio as gr
3
 
4
- def update_input_visibility(choice, upload_component, url_component, base64_component):
5
  """
6
- Updates the visibility of input components based on the selected input method.
7
 
8
  Args:
9
  choice (str): The selected input method ("Upload File", "Enter URL", "Enter Base64").
10
- upload_component (gr.components): The Gradio component for file upload.
11
- url_component (gr.components): The Gradio component for URL input.
12
- base64_component (gr.components): The Gradio component for Base64 input.
13
 
14
  Returns:
15
- tuple: A tuple containing the updated Gradio components with their visibility set.
16
  """
17
  if choice == "Upload File":
18
  return (
19
- upload_component.update(visible=True),
20
- url_component.update(visible=False),
21
- base64_component.update(visible=False),
22
  )
23
  elif choice == "Enter URL":
24
  return (
25
- upload_component.update(visible=False),
26
- url_component.update(visible=True),
27
- base64_component.update(visible=False),
28
  )
29
  elif choice == "Enter Base64":
30
  return (
31
- upload_component.update(visible=False),
32
- url_component.update(visible=False),
33
- base64_component.update(visible=True),
34
  )
35
  else: # Default or unexpected
36
  return (
37
- upload_component.update(visible=True),
38
- url_component.update(visible=False),
39
- base64_component.update(visible=False),
40
  )
 
1
  # Utility functions for UI components
2
  import gradio as gr
3
 
4
+ def update_input_visibility(choice):
5
  """
6
+ Returns updates to the visibility of input components based on the selected input method.
7
 
8
  Args:
9
  choice (str): The selected input method ("Upload File", "Enter URL", "Enter Base64").
 
 
 
10
 
11
  Returns:
12
+ tuple: A tuple containing Gradio Update objects for the visibility of the input components.
13
  """
14
  if choice == "Upload File":
15
  return (
16
+ gr.update(visible=True),
17
+ gr.update(visible=False),
18
+ gr.update(visible=False),
19
  )
20
  elif choice == "Enter URL":
21
  return (
22
+ gr.update(visible=False),
23
+ gr.update(visible=True),
24
+ gr.update(visible=False),
25
  )
26
  elif choice == "Enter Base64":
27
  return (
28
+ gr.update(visible=False),
29
+ gr.update(visible=False),
30
+ gr.update(visible=True),
31
  )
32
  else: # Default or unexpected
33
  return (
34
+ gr.update(visible=True),
35
+ gr.update(visible=False),
36
+ gr.update(visible=False),
37
  )