GeorgeSherif commited on
Commit
5b3d599
·
1 Parent(s): cb7137d
Files changed (1) hide show
  1. app.py +10 -10
app.py CHANGED
@@ -76,7 +76,7 @@ def get_next_image(session_data):
76
  # Function to save the annotation to Hugging Face dataset and fetch the next image
77
  def save_annotation(caption, session_data):
78
  if session_data["current_image"] is None:
79
- return gr.update(visible=False), gr.update(value="All images have been annotated!")
80
 
81
  with lock:
82
  image_id = session_data["current_image"]
@@ -100,14 +100,14 @@ def save_annotation(caption, session_data):
100
  # Fetch the next image
101
  next_image = get_next_image(session_data)
102
  if next_image:
103
- next_caption = get_caption_for_image_id(image_id) # Retrieve the caption for the new image
104
- return gr.update(value=next_image), gr.update(value=next_caption or "")
105
  else:
106
- return gr.update(visible=False), gr.update(value="All images have been annotated!")
107
 
108
  # Function to skip the current image
109
- def skip_image(session_data):
110
- return save_annotation("skip", session_data)
111
 
112
  def initialize_interface(session_data):
113
  next_image = get_next_image(session_data)
@@ -121,7 +121,7 @@ def initialize_interface(session_data):
121
  # Build the Gradio interface
122
  with gr.Blocks() as demo:
123
  gr.Markdown("# Image Captioning Tool")
124
- gr.Markdown("Please provide a caption for each image displayed. Click 'Submit' after writing your caption, or type 'skip' if you don’t want to annotate this image.")
125
 
126
  session_data = gr.State({"current_image": None}) # Session-specific state
127
 
@@ -130,11 +130,11 @@ with gr.Blocks() as demo:
130
  caption = gr.Textbox(placeholder="Enter caption here...")
131
  existing_caption = gr.Textbox(label="Existing Caption", interactive=False) # Display existing caption
132
  submit = gr.Button("Submit")
133
- skip = gr.Button("Skip") # Skip button
134
 
135
  # Define actions for buttons
136
- submit.click(fn=save_annotation, inputs=[caption, session_data], outputs=[image, caption])
137
- skip.click(fn=skip_image, inputs=session_data, outputs=[image, caption])
138
 
139
  # Load initial image
140
  demo.load(fn=initialize_interface, inputs=session_data, outputs=[image, existing_caption])
 
76
  # Function to save the annotation to Hugging Face dataset and fetch the next image
77
  def save_annotation(caption, session_data):
78
  if session_data["current_image"] is None:
79
+ return gr.update(visible=False), gr.update(value="All images have been annotated!"), gr.update(value="")
80
 
81
  with lock:
82
  image_id = session_data["current_image"]
 
100
  # Fetch the next image
101
  next_image = get_next_image(session_data)
102
  if next_image:
103
+ next_caption = get_caption_for_image_id(os.path.basename(next_image)) # Retrieve the caption for the new image
104
+ return gr.update(value=next_image), gr.update(value=""), gr.update(value=next_caption or "")
105
  else:
106
+ return gr.update(visible=False), gr.update(value="All images have been annotated!"), gr.update(value="")
107
 
108
  # Function to skip the current image
109
+ # def skip_image(session_data):
110
+ # return save_annotation("skip", session_data)
111
 
112
  def initialize_interface(session_data):
113
  next_image = get_next_image(session_data)
 
121
  # Build the Gradio interface
122
  with gr.Blocks() as demo:
123
  gr.Markdown("# Image Captioning Tool")
124
+ gr.Markdown("Please provide your caption in Egyptian Arabic 'Masri'")
125
 
126
  session_data = gr.State({"current_image": None}) # Session-specific state
127
 
 
130
  caption = gr.Textbox(placeholder="Enter caption here...")
131
  existing_caption = gr.Textbox(label="Existing Caption", interactive=False) # Display existing caption
132
  submit = gr.Button("Submit")
133
+ # skip = gr.Button("Skip") # Skip button
134
 
135
  # Define actions for buttons
136
+ submit.click(fn=save_annotation, inputs=[caption, session_data], outputs=[image, caption, existing_caption])
137
+ # skip.click(fn=skip_image, inputs=session_data, outputs=[image, caption])
138
 
139
  # Load initial image
140
  demo.load(fn=initialize_interface, inputs=session_data, outputs=[image, existing_caption])