GeorgeIbrahim commited on
Commit
10df191
·
1 Parent(s): 31f35b1
Files changed (1) hide show
  1. app.py +31 -24
app.py CHANGED
@@ -7,7 +7,11 @@ from huggingface_hub import login
7
  import json
8
  import re
9
 
10
- reset = True
 
 
 
 
11
 
12
  # Authenticate with Hugging Face
13
  token = os.getenv("HUGGINGFACE_TOKEN")
@@ -67,28 +71,28 @@ except Exception as e:
67
 
68
 
69
  # Initialize or reset data as needed based on the `reset` flag
70
- if reset:
71
- # Clear the annotation counts
72
- annotation_counts = {}
73
- shown_counts = {} # If you are tracking shown counts separately for images
74
-
75
- # Optionally, clear or reinitialize the dataset
76
- features = Features({
77
- 'image_id': Value(dtype='string'),
78
- 'caption': Value(dtype='string'),
79
- 'annotation_count': Value(dtype='int32'),
80
- 'split': Value(dtype='string')
81
- })
82
- dataset = Dataset.from_dict({
83
- 'image_id': [],
84
- 'caption': [],
85
- 'annotation_count': [],
86
- 'split': []
87
- }, features=features)
88
 
89
- # Push the reset dataset to Hugging Face or perform other necessary actions
90
- dataset.push_to_hub(dataset_name)
91
- print("Data has been reset.")
92
 
93
  image_folder = "images"
94
  image_files = [f for f in os.listdir(image_folder) if f.endswith(('.png', '.jpg', '.jpeg'))]
@@ -232,7 +236,10 @@ with gr.Blocks() as demo:
232
  image = gr.Image()
233
  caption = gr.Textbox(placeholder="Enter caption here...")
234
  existing_caption = gr.Textbox(label="Existing Caption", interactive=False) # Display existing caption
235
- submit = gr.Button("Submit")
 
 
 
236
 
237
  # Define actions for buttons
238
  submit.click(fn=save_annotation, inputs=[caption, session_data], outputs=[image, caption, existing_caption])
@@ -240,4 +247,4 @@ with gr.Blocks() as demo:
240
  # Load initial image
241
  demo.load(fn=initialize_interface, inputs=session_data, outputs=[image, existing_caption])
242
 
243
- demo.launch(share=True)
 
7
  import json
8
  import re
9
 
10
+ # reset = False
11
+
12
+ def check_word_count(caption):
13
+ # Check if the caption has 3 or more words
14
+ return gr.update(interactive=len(caption.split()) >= 3)
15
 
16
  # Authenticate with Hugging Face
17
  token = os.getenv("HUGGINGFACE_TOKEN")
 
71
 
72
 
73
  # Initialize or reset data as needed based on the `reset` flag
74
+ # if reset:
75
+ # # Clear the annotation counts
76
+ # annotation_counts = {}
77
+ # shown_counts = {} # If you are tracking shown counts separately for images
78
+
79
+ # # Optionally, clear or reinitialize the dataset
80
+ # features = Features({
81
+ # 'image_id': Value(dtype='string'),
82
+ # 'caption': Value(dtype='string'),
83
+ # 'annotation_count': Value(dtype='int32'),
84
+ # 'split': Value(dtype='string')
85
+ # })
86
+ # dataset = Dataset.from_dict({
87
+ # 'image_id': [],
88
+ # 'caption': [],
89
+ # 'annotation_count': [],
90
+ # 'split': []
91
+ # }, features=features)
92
 
93
+ # # Push the reset dataset to Hugging Face or perform other necessary actions
94
+ # dataset.push_to_hub(dataset_name)
95
+ # print("Data has been reset.")
96
 
97
  image_folder = "images"
98
  image_files = [f for f in os.listdir(image_folder) if f.endswith(('.png', '.jpg', '.jpeg'))]
 
236
  image = gr.Image()
237
  caption = gr.Textbox(placeholder="Enter caption here...")
238
  existing_caption = gr.Textbox(label="Existing Caption", interactive=False) # Display existing caption
239
+ submit = gr.Button("Submit", interactive=False) # Initially disabled
240
+
241
+ # Enable/disable the submit button based on word count
242
+ caption.change(fn=check_word_count, inputs=caption, outputs=submit)
243
 
244
  # Define actions for buttons
245
  submit.click(fn=save_annotation, inputs=[caption, session_data], outputs=[image, caption, existing_caption])
 
247
  # Load initial image
248
  demo.load(fn=initialize_interface, inputs=session_data, outputs=[image, existing_caption])
249
 
250
+ demo.launch(share=True)