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,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,7 @@ 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, "cultural_relevance": 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, "email": email}
|
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,7 +49,7 @@ 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 |
-
return input_img, f"Your text response: {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}"
|
53 |
def clear_inputs():
|
54 |
return None, "", None, None, "", None, None, "", "", ""
|
55 |
setup_hf_dataset()
|
@@ -59,7 +59,7 @@ with gr.Blocks(theme='1024m/1024m-1') as gradio_app:
|
|
59 |
with gr.Row():
|
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)
|
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")
|
@@ -67,8 +67,10 @@ with gr.Blocks(theme='1024m/1024m-1') as gradio_app:
|
|
67 |
with gr.Column(scale=1):
|
68 |
se_asia_relevance = gr.Radio(choices=["Yes. Unique to South Asia", "Yes, people will likely think of South Asia when seeing the picture, but it may have low degree of similarity to other cultures.", "Maybe, this culture did not originate from South Asia, but it's quite dominant in South Asia", "Not really. It has some affiliation to South Asia, but actually does not represent South Asia or has stronger affiliation to cultures outside South Asia", "No. Totally unrelated to South Asia"], label="Is the image culturally relevant in South Asia?")
|
69 |
culture_knowledge = gr.Radio(choices=["I'm from this country/culture", "I checked online resources (e.g., Wikipedia, articles, blogs)"], label="How do you know about this culture?", info="Please do not consult LLMs (e.g., GPT-4o, Claude, Command-R, etc.)")
|
70 |
-
native_caption = gr.Textbox(label="Caption in Native Language:", placeholder="Enter caption in the native language of the culture depicted")
|
71 |
-
english_caption = gr.Textbox(label="English Caption:", placeholder="Enter caption in English")
|
|
|
|
|
72 |
with gr.Row():
|
73 |
clear_btn = gr.Button("Clear")
|
74 |
submit_btn = gr.Button("Submit")
|
@@ -83,7 +85,7 @@ with gr.Blocks(theme='1024m/1024m-1') as gradio_app:
|
|
83 |
output_native = gr.Text(label="Native Language Caption")
|
84 |
output_english = gr.Text(label="English Caption")
|
85 |
country_dropdown.change(fn=update_state_dropdown, inputs=country_dropdown, outputs=state_dropdown)
|
86 |
-
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, email_input], outputs=[output_img, output_text, output_location, output_relevance, output_knowledge, output_native, output_english])
|
87 |
-
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, email_input])
|
88 |
if __name__ == "__main__":
|
89 |
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):
|
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, "cultural_relevance": 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 |
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 |
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 |
+
return input_img, f"Your text response: {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}"
|
53 |
def clear_inputs():
|
54 |
return None, "", None, None, "", None, None, "", "", ""
|
55 |
setup_hf_dataset()
|
|
|
59 |
with gr.Row():
|
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")
|
|
|
67 |
with gr.Column(scale=1):
|
68 |
se_asia_relevance = gr.Radio(choices=["Yes. Unique to South Asia", "Yes, people will likely think of South Asia when seeing the picture, but it may have low degree of similarity to other cultures.", "Maybe, this culture did not originate from South Asia, but it's quite dominant in South Asia", "Not really. It has some affiliation to South Asia, but actually does not represent South Asia or has stronger affiliation to cultures outside South Asia", "No. Totally unrelated to South Asia"], label="Is the image culturally relevant in South Asia?")
|
69 |
culture_knowledge = gr.Radio(choices=["I'm from this country/culture", "I checked online resources (e.g., Wikipedia, articles, blogs)"], label="How do you know about this culture?", info="Please do not consult LLMs (e.g., GPT-4o, Claude, Command-R, etc.)")
|
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="description",info="1-2 word any description")
|
74 |
with gr.Row():
|
75 |
clear_btn = gr.Button("Clear")
|
76 |
submit_btn = gr.Button("Submit")
|
|
|
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()
|