Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -27,7 +27,7 @@ def update_state_dropdown(country):
|
|
27 |
if country in states_by_country:
|
28 |
return gr.Dropdown(choices=states_by_country[country], label=f"State/Province in {country}:", interactive=True)
|
29 |
return gr.Dropdown(choices=[], label="State/Province:", interactive=True)
|
30 |
-
def process_submission(input_img, language, country, state, city, se_asia_relevance, culture_knowledge, native_caption, english_caption,code_mixed_caption,domain,email):
|
31 |
submission_id = str(uuid.uuid4())
|
32 |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
33 |
image_path = None
|
@@ -36,7 +36,9 @@ def process_submission(input_img, language, country, state, city, se_asia_releva
|
|
36 |
image_path = os.path.join("uploaded_images", image_filename)
|
37 |
if isinstance(input_img, str): shutil.copy(input_img, image_path)
|
38 |
else: input_img.save(image_path)
|
39 |
-
submission_data = {"id": submission_id, "timestamp": timestamp, "image_filename": os.path.basename(image_path) if image_path else None, "
|
|
|
|
|
40 |
json_filename = f"{timestamp}.json"
|
41 |
json_path = os.path.join("submissions", json_filename)
|
42 |
with open(json_path, "w") as f: json.dump(submission_data, f, indent=2)
|
@@ -49,9 +51,12 @@ def process_submission(input_img, language, country, state, city, se_asia_releva
|
|
49 |
print(f"Submission {submission_id} uploaded to Hugging Face Dataset")
|
50 |
except Exception as e: print(f"Error uploading to dataset: {e}")
|
51 |
location_info = f"Location: {city}, {state}, {country}" if state else f"Location: {city}, {country}"
|
52 |
-
|
|
|
|
|
|
|
53 |
def clear_inputs():
|
54 |
-
return None, "", None, None, "", None, None, "", "", ""
|
55 |
setup_hf_dataset()
|
56 |
with gr.Blocks(theme='1024m/1024m-1') as gradio_app:
|
57 |
gr.Markdown("# South Asian Image Data Collection")
|
@@ -60,6 +65,7 @@ with gr.Blocks(theme='1024m/1024m-1') as gradio_app:
|
|
60 |
with gr.Column(scale=1):
|
61 |
input_img = gr.Image(label="Upload an image", sources=['upload', 'webcam'], type="pil")
|
62 |
language = gr.Dropdown(choices=south_asian_languages, label="Language:", info="Select the native language relevant to the image", interactive=True,value=south_asian_languages[-1])
|
|
|
63 |
country_dropdown = gr.Dropdown(choices=["None","India", "Pakistan", "Bangladesh", "Afghanistan", "Bhutan", "Nepal", "Sri Lanka"], label="Country where the image was taken:", interactive=True)
|
64 |
state_dropdown = gr.Dropdown(choices=[], label="State/Province:", interactive=True)
|
65 |
city_textbox = gr.Textbox(label="City where the image was taken:", placeholder="Enter city name")
|
@@ -70,7 +76,7 @@ with gr.Blocks(theme='1024m/1024m-1') as gradio_app:
|
|
70 |
native_caption = gr.Textbox(label="Caption in Native Language:", placeholder="Enter caption in the native language of the culture depicted", info="in native script ONLY")
|
71 |
english_caption = gr.Textbox(label="English Caption:", placeholder="Enter caption in English", info="in english script ONLY")
|
72 |
code_mixed_caption = gr.Textbox(label="Code-Mixed Caption:", placeholder="Enter caption in code-mixed", info="in english script ONLY")
|
73 |
-
domain = gr.Textbox(label="Domain:",placeholder="
|
74 |
with gr.Row():
|
75 |
clear_btn = gr.Button("Clear")
|
76 |
submit_btn = gr.Button("Submit")
|
@@ -85,7 +91,7 @@ with gr.Blocks(theme='1024m/1024m-1') as gradio_app:
|
|
85 |
output_native = gr.Text(label="Native Language Caption")
|
86 |
output_english = gr.Text(label="English Caption")
|
87 |
country_dropdown.change(fn=update_state_dropdown, inputs=country_dropdown, outputs=state_dropdown)
|
88 |
-
submit_btn.click(fn=process_submission, inputs=[input_img, language, country_dropdown, state_dropdown, city_textbox, se_asia_relevance, culture_knowledge, native_caption, english_caption,code_mixed_caption,domain, email_input], outputs=[output_img, output_text, output_location, output_relevance, output_knowledge, output_native, output_english])
|
89 |
-
clear_btn.click(fn=clear_inputs, inputs=[], outputs=[input_img, language, country_dropdown, state_dropdown, city_textbox, se_asia_relevance, culture_knowledge, native_caption, english_caption,code_mixed_caption,domain, email_input])
|
90 |
if __name__ == "__main__":
|
91 |
gradio_app.launch()
|
|
|
27 |
if country in states_by_country:
|
28 |
return gr.Dropdown(choices=states_by_country[country], label=f"State/Province in {country}:", interactive=True)
|
29 |
return gr.Dropdown(choices=[], label="State/Province:", interactive=True)
|
30 |
+
def process_submission(input_img, language, country, state, city, se_asia_relevance, culture_knowledge, native_caption, english_caption,code_mixed_caption,domain,email,other_language=None):
|
31 |
submission_id = str(uuid.uuid4())
|
32 |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
33 |
image_path = None
|
|
|
36 |
image_path = os.path.join("uploaded_images", image_filename)
|
37 |
if isinstance(input_img, str): shutil.copy(input_img, image_path)
|
38 |
else: input_img.save(image_path)
|
39 |
+
submission_data = {"id": submission_id, "timestamp": timestamp, "image_filename": os.path.basename(image_path) if image_path else None, "language": language, "country": country, "state": state, "city": city, "se_asia_relevance": se_asia_relevance, "cultural_knowledge_source": culture_knowledge, "native_caption": native_caption, "english_caption": english_caption,"code_mixed_caption": code_mixed_caption,"domain":domain, "email": email}
|
40 |
+
if other_language is not None:
|
41 |
+
submission_data["other language"] = other_language
|
42 |
json_filename = f"{timestamp}.json"
|
43 |
json_path = os.path.join("submissions", json_filename)
|
44 |
with open(json_path, "w") as f: json.dump(submission_data, f, indent=2)
|
|
|
51 |
print(f"Submission {submission_id} uploaded to Hugging Face Dataset")
|
52 |
except Exception as e: print(f"Error uploading to dataset: {e}")
|
53 |
location_info = f"Location: {city}, {state}, {country}" if state else f"Location: {city}, {country}"
|
54 |
+
response = [input_img, f"Language: {language}", 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}" , f"Code mixed caption: {code_mixed_caption}", f"Domain: {domain}"]
|
55 |
+
if other_language is not None:
|
56 |
+
response.append(f"Other language: {other_language}")
|
57 |
+
return tuple(response)
|
58 |
def clear_inputs():
|
59 |
+
return None, "OTHER", "", None, None, "", "", None, None, "", "", "", ""
|
60 |
setup_hf_dataset()
|
61 |
with gr.Blocks(theme='1024m/1024m-1') as gradio_app:
|
62 |
gr.Markdown("# South Asian Image Data Collection")
|
|
|
65 |
with gr.Column(scale=1):
|
66 |
input_img = gr.Image(label="Upload an image", sources=['upload', 'webcam'], type="pil")
|
67 |
language = gr.Dropdown(choices=south_asian_languages, label="Language:", info="Select the native language relevant to the image", interactive=True,value=south_asian_languages[-1])
|
68 |
+
other_language = gr.Textbox(label="Other Language:",placeholder="optional",info="Name of the language if not listed above")
|
69 |
country_dropdown = gr.Dropdown(choices=["None","India", "Pakistan", "Bangladesh", "Afghanistan", "Bhutan", "Nepal", "Sri Lanka"], label="Country where the image was taken:", interactive=True)
|
70 |
state_dropdown = gr.Dropdown(choices=[], label="State/Province:", interactive=True)
|
71 |
city_textbox = gr.Textbox(label="City where the image was taken:", placeholder="Enter city name")
|
|
|
76 |
native_caption = gr.Textbox(label="Caption in Native Language:", placeholder="Enter caption in the native language of the culture depicted", info="in native script ONLY")
|
77 |
english_caption = gr.Textbox(label="English Caption:", placeholder="Enter caption in English", info="in english script ONLY")
|
78 |
code_mixed_caption = gr.Textbox(label="Code-Mixed Caption:", placeholder="Enter caption in code-mixed", info="in english script ONLY")
|
79 |
+
domain = gr.Textbox(label="Domain:",placeholder="Description",info="1-2 word any description")
|
80 |
with gr.Row():
|
81 |
clear_btn = gr.Button("Clear")
|
82 |
submit_btn = gr.Button("Submit")
|
|
|
91 |
output_native = gr.Text(label="Native Language Caption")
|
92 |
output_english = gr.Text(label="English Caption")
|
93 |
country_dropdown.change(fn=update_state_dropdown, inputs=country_dropdown, outputs=state_dropdown)
|
94 |
+
submit_btn.click(fn=process_submission, inputs=[input_img, language, country_dropdown, state_dropdown, city_textbox, se_asia_relevance, culture_knowledge, native_caption, english_caption,code_mixed_caption,domain, email_input,other_language], outputs=[output_img, output_text, output_location, output_relevance, output_knowledge, output_native, output_english])
|
95 |
+
clear_btn.click(fn=clear_inputs, inputs=[], outputs=[input_img, language,other_language, country_dropdown, state_dropdown, city_textbox, se_asia_relevance, culture_knowledge, native_caption, english_caption,code_mixed_caption,domain, email_input])
|
96 |
if __name__ == "__main__":
|
97 |
gradio_app.launch()
|