minemaster01 commited on
Commit
875a4b6
·
verified ·
1 Parent(s): 76c5b42

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -26
app.py CHANGED
@@ -75,7 +75,7 @@ def update_state_dropdown(country):
75
  return gr.Dropdown(choices=states_by_country[country], label=f"State/Province in {country}:", interactive=True)
76
  return gr.Dropdown(choices=[], label="State/Province:", interactive=True)
77
 
78
- def process_submission(input_img, text_answer, country, state, city, se_asia_relevance, culture_knowledge, native_caption, english_caption):
79
  # Generate unique ID for this submission
80
  submission_id = str(uuid.uuid4())
81
  timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
@@ -97,6 +97,7 @@ def process_submission(input_img, text_answer, country, state, city, se_asia_rel
97
  submission_data = {
98
  "id": submission_id,
99
  "timestamp": timestamp,
 
100
  "image_filename": os.path.basename(image_path) if image_path else None,
101
  "cultural_relevance": text_answer,
102
  "country": country,
@@ -104,8 +105,8 @@ def process_submission(input_img, text_answer, country, state, city, se_asia_rel
104
  "city": city,
105
  "se_asia_relevance": se_asia_relevance,
106
  "cultural_knowledge_source": culture_knowledge,
107
- "native_caption": native_caption,
108
- "english_caption": english_caption
109
  }
110
 
111
  # Save the data as JSON
@@ -141,7 +142,7 @@ def process_submission(input_img, text_answer, country, state, city, se_asia_rel
141
 
142
  # Return values to display in the interface
143
  location_info = f"Location: {city}, {state}, {country}" if state else f"Location: {city}, {country}"
144
- return input_img, f"Your text response: {text_answer}", f"Selected location: {location_info}", f"SE Asia relevance: {se_asia_relevance}", f"Cultural knowledge source: {culture_knowledge}", f"Native caption: {native_caption}", f"English caption: {english_caption}"
145
 
146
  # Initialize the dataset
147
  setup_hf_dataset()
@@ -150,6 +151,9 @@ with gr.Blocks() as gradio_app:
150
  gr.Markdown("# South Asian Image Data Collection")
151
  gr.Markdown("Upload an image and answer questions about its cultural significance.")
152
 
 
 
 
153
  with gr.Row():
154
  input_img = gr.Image(label="Upload an image", sources=['upload', 'webcam'], type="pil")
155
 
@@ -204,26 +208,38 @@ with gr.Blocks() as gradio_app:
204
  with gr.Row():
205
  submit_btn = gr.Button("Submit")
206
 
207
- with gr.Row():
208
- output_img = gr.Image(label="Submitted Image")
209
-
210
- with gr.Row():
211
- output_text = gr.Text(label="Text Response")
212
-
213
- with gr.Row():
214
- output_location = gr.Text(label="Location Information")
215
-
216
- with gr.Row():
217
- output_relevance = gr.Text(label="South Asia Cultural Relevance")
218
-
219
- with gr.Row():
220
- output_knowledge = gr.Text(label="Cultural Knowledge Source")
221
-
222
- with gr.Row():
223
- output_native = gr.Text(label="Native Language Caption")
 
 
 
 
 
 
 
 
 
224
 
225
- with gr.Row():
226
- output_english = gr.Text(label="English Caption")
 
 
 
227
 
228
  # Set up event handlers
229
  country_dropdown.change(
@@ -233,7 +249,7 @@ with gr.Blocks() as gradio_app:
233
  )
234
 
235
  submit_btn.click(
236
- fn=process_submission,
237
  inputs=[
238
  input_img,
239
  text_answer,
@@ -242,8 +258,9 @@ with gr.Blocks() as gradio_app:
242
  city_textbox,
243
  se_asia_relevance,
244
  culture_knowledge,
 
245
  native_caption,
246
- english_caption
247
  ],
248
  outputs=[
249
  output_img,
@@ -251,8 +268,9 @@ with gr.Blocks() as gradio_app:
251
  output_location,
252
  output_relevance,
253
  output_knowledge,
 
254
  output_native,
255
- output_english
256
  ]
257
  )
258
 
 
75
  return gr.Dropdown(choices=states_by_country[country], label=f"State/Province in {country}:", interactive=True)
76
  return gr.Dropdown(choices=[], label="State/Province:", interactive=True)
77
 
78
+ def process_submission(input_img, text_answer, country, state, city, se_asia_relevance, culture_knowledge, english_caption, native_caption, email):
79
  # Generate unique ID for this submission
80
  submission_id = str(uuid.uuid4())
81
  timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
 
97
  submission_data = {
98
  "id": submission_id,
99
  "timestamp": timestamp,
100
+ "email": email, # Add email as unique identifier
101
  "image_filename": os.path.basename(image_path) if image_path else None,
102
  "cultural_relevance": text_answer,
103
  "country": country,
 
105
  "city": city,
106
  "se_asia_relevance": se_asia_relevance,
107
  "cultural_knowledge_source": culture_knowledge,
108
+ "english_caption": english_caption,
109
+ "native_caption": native_caption
110
  }
111
 
112
  # Save the data as JSON
 
142
 
143
  # Return values to display in the interface
144
  location_info = f"Location: {city}, {state}, {country}" if state else f"Location: {city}, {country}"
145
+ return input_img, f"Your text response: {text_answer}", f"Selected location: {location_info}", f"SE Asia relevance: {se_asia_relevance}", f"Cultural knowledge source: {culture_knowledge}", f"English caption: {english_caption}", f"Native caption: {native_caption}", f"Email: {email}"
146
 
147
  # Initialize the dataset
148
  setup_hf_dataset()
 
151
  gr.Markdown("# South Asian Image Data Collection")
152
  gr.Markdown("Upload an image and answer questions about its cultural significance.")
153
 
154
+ with gr.Row():
155
+ email_input = gr.Textbox(label="Your Email:", placeholder="Enter your email address (will be used as your contributor ID)", info="Your email will be stored with your submission as a unique identifier")
156
+
157
  with gr.Row():
158
  input_img = gr.Image(label="Upload an image", sources=['upload', 'webcam'], type="pil")
159
 
 
208
  with gr.Row():
209
  submit_btn = gr.Button("Submit")
210
 
211
+ # Output elements
212
+ output_elements = gr.Group(visible=False)
213
+ with output_elements:
214
+ with gr.Row():
215
+ output_img = gr.Image(label="Submitted Image")
216
+
217
+ with gr.Row():
218
+ output_text = gr.Text(label="Text Response")
219
+
220
+ with gr.Row():
221
+ output_location = gr.Text(label="Location Information")
222
+
223
+ with gr.Row():
224
+ output_relevance = gr.Text(label="South Asia Cultural Relevance")
225
+
226
+ with gr.Row():
227
+ output_knowledge = gr.Text(label="Cultural Knowledge Source")
228
+
229
+ with gr.Row():
230
+ output_english = gr.Text(label="English Caption")
231
+
232
+ with gr.Row():
233
+ output_native = gr.Text(label="Native Language Caption")
234
+
235
+ with gr.Row():
236
+ output_email = gr.Text(label="Email")
237
 
238
+ # Add function to show outputs after submission
239
+ def show_outputs(*args):
240
+ output_values = process_submission(*args)
241
+ output_elements.visible = True
242
+ return output_values
243
 
244
  # Set up event handlers
245
  country_dropdown.change(
 
249
  )
250
 
251
  submit_btn.click(
252
+ fn=show_outputs,
253
  inputs=[
254
  input_img,
255
  text_answer,
 
258
  city_textbox,
259
  se_asia_relevance,
260
  culture_knowledge,
261
+ english_caption,
262
  native_caption,
263
+ email_input
264
  ],
265
  outputs=[
266
  output_img,
 
268
  output_location,
269
  output_relevance,
270
  output_knowledge,
271
+ output_english,
272
  output_native,
273
+ output_email
274
  ]
275
  )
276