justinkay
commited on
Commit
Β·
783e612
1
Parent(s):
eaf554e
Show species guide during demo
Browse files
app.py
CHANGED
|
@@ -61,6 +61,68 @@ MODEL_INFO = [
|
|
| 61 |
DEMO_LEARNING_RATE = 0.05 # don't use default; use something more fun
|
| 62 |
DEMO_ALPHA = 0.25
|
| 63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
# load image metadata
|
| 65 |
images_data = []
|
| 66 |
for annotation in tqdm(data['annotations'], desc='Loading annotations'):
|
|
@@ -669,64 +731,7 @@ with gr.Blocks(title="CODA: Wildlife Photo Classification Challenge",
|
|
| 669 |
|
| 670 |
# Species guide content (initially hidden)
|
| 671 |
with gr.Column(visible=False) as species_guide_content:
|
| 672 |
-
|
| 673 |
-
# Species Classification Guide
|
| 674 |
-
|
| 675 |
-
### Learn to identify the five wildlife species in this demo.
|
| 676 |
-
|
| 677 |
-
## Jaguar
|
| 678 |
-
""")
|
| 679 |
-
|
| 680 |
-
gr.Image("species_id/jaguar.jpg", label="Jaguar example image", show_label=False)
|
| 681 |
-
|
| 682 |
-
gr.Markdown("""
|
| 683 |
-
The largest cat in the Americas, with a stocky, muscular build and a broad head; its golden coat is patterned with rosettes that often have central spots inside.
|
| 684 |
-
|
| 685 |
-
----
|
| 686 |
-
|
| 687 |
-
## Ocelot
|
| 688 |
-
|
| 689 |
-
""")
|
| 690 |
-
|
| 691 |
-
gr.Image("species_id/ocelot.jpg", label="Ocelot example image", show_label=False)
|
| 692 |
-
|
| 693 |
-
gr.Markdown("""
|
| 694 |
-
A medium-sized spotted cat about twice the size of a domestic cat, with a slender body, large eyes, and striking chain-link or stripe-like rosettes. It differs from jaguars by its smaller size, leaner build, and more elongated markings.
|
| 695 |
-
|
| 696 |
-
----
|
| 697 |
-
|
| 698 |
-
## Mountain Lion
|
| 699 |
-
""")
|
| 700 |
-
|
| 701 |
-
gr.Image("species_id/mountainlion.jpg", label="Mountain lion example image", show_label=False)
|
| 702 |
-
|
| 703 |
-
gr.Markdown("""
|
| 704 |
-
Also called cougar or puma, this cat has a plain tawny or grayish coat without spots or rosettes. Its long tail and uniformly colored fur distinguish it from jaguars and ocelots.
|
| 705 |
-
|
| 706 |
-
----
|
| 707 |
-
|
| 708 |
-
## Common Eland
|
| 709 |
-
|
| 710 |
-
""")
|
| 711 |
-
|
| 712 |
-
gr.Image("species_id/commoneland.jpg", label="Eland example image", show_label=False)
|
| 713 |
-
|
| 714 |
-
gr.Markdown("""
|
| 715 |
-
The largest antelope species, with a robust body, spiraled horns on both sexes, and a characteristic dewlap hanging from the throat. It differs from waterbuck by its lighter tan coat, faint body stripes, and massive size.
|
| 716 |
-
|
| 717 |
-
----
|
| 718 |
-
|
| 719 |
-
## Waterbuck
|
| 720 |
-
""")
|
| 721 |
-
|
| 722 |
-
gr.Image("species_id/waterbuck.jpg", label="Waterbuck example image", show_label=False)
|
| 723 |
-
|
| 724 |
-
gr.Markdown("""
|
| 725 |
-
A shaggy, dark brown antelope recognized by its white rump ring and backward-curving horns in males. Smaller and darker than the common eland, waterbuck prefer wet habitats and lack the eland's throat dewlap.
|
| 726 |
-
|
| 727 |
-
----
|
| 728 |
-
|
| 729 |
-
""")
|
| 730 |
|
| 731 |
# Add spacing before buttons
|
| 732 |
gr.HTML("<div style='margin-top: 0.1em;'></div>")
|
|
@@ -787,6 +792,16 @@ with gr.Blocks(title="CODA: Wildlife Photo Classification Challenge",
|
|
| 787 |
[Placeholder]
|
| 788 |
""")
|
| 789 |
selection_help_close = gr.Button("Close", variant="secondary")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 790 |
|
| 791 |
# Two panels with bar charts
|
| 792 |
with gr.Row():
|
|
@@ -845,8 +860,10 @@ with gr.Blocks(title="CODA: Wildlife Photo Classification Challenge",
|
|
| 845 |
if DEBUG_MODE:
|
| 846 |
delete_button = gr.Button("ποΈ Delete Current Image", variant="stop", size="lg")
|
| 847 |
|
| 848 |
-
# Add
|
| 849 |
-
|
|
|
|
|
|
|
| 850 |
|
| 851 |
# Set up button interactions
|
| 852 |
def start_demo():
|
|
@@ -953,6 +970,12 @@ with gr.Blocks(title="CODA: Wildlife Photo Classification Challenge",
|
|
| 953 |
def hide_selection_help():
|
| 954 |
return gr.update(visible=False)
|
| 955 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 956 |
popup_start_button.click(
|
| 957 |
fn=start_demo,
|
| 958 |
outputs=[image_display, status_with_help, model_predictions_display, prob_plot, accuracy_plot, popup_overlay, result_display, selection_help_button]
|
|
@@ -1004,6 +1027,17 @@ with gr.Blocks(title="CODA: Wildlife Photo Classification Challenge",
|
|
| 1004 |
outputs=[selection_help_popup]
|
| 1005 |
)
|
| 1006 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1007 |
for btn in species_buttons:
|
| 1008 |
btn.click(
|
| 1009 |
fn=check_answer,
|
|
|
|
| 61 |
DEMO_LEARNING_RATE = 0.05 # don't use default; use something more fun
|
| 62 |
DEMO_ALPHA = 0.25
|
| 63 |
|
| 64 |
+
def create_species_guide_content():
|
| 65 |
+
"""Create the species identification guide content"""
|
| 66 |
+
with gr.Column():
|
| 67 |
+
gr.Markdown("""
|
| 68 |
+
# Species Classification Guide
|
| 69 |
+
|
| 70 |
+
### Learn to identify the five wildlife species in this demo.
|
| 71 |
+
|
| 72 |
+
## Jaguar
|
| 73 |
+
""")
|
| 74 |
+
|
| 75 |
+
gr.Image("species_id/jaguar.jpg", label="Jaguar example image", show_label=False)
|
| 76 |
+
|
| 77 |
+
gr.Markdown("""
|
| 78 |
+
The largest cat in the Americas, with a stocky, muscular build and a broad head; its golden coat is patterned with rosettes that often have central spots inside.
|
| 79 |
+
|
| 80 |
+
----
|
| 81 |
+
|
| 82 |
+
## Ocelot
|
| 83 |
+
|
| 84 |
+
""")
|
| 85 |
+
|
| 86 |
+
gr.Image("species_id/ocelot.jpg", label="Ocelot example image", show_label=False)
|
| 87 |
+
|
| 88 |
+
gr.Markdown("""
|
| 89 |
+
A medium-sized spotted cat about twice the size of a domestic cat, with a slender body, large eyes, and striking chain-link or stripe-like rosettes. It differs from jaguars by its smaller size, leaner build, and more elongated markings.
|
| 90 |
+
|
| 91 |
+
----
|
| 92 |
+
|
| 93 |
+
## Mountain Lion
|
| 94 |
+
""")
|
| 95 |
+
|
| 96 |
+
gr.Image("species_id/mountainlion.jpg", label="Mountain lion example image", show_label=False)
|
| 97 |
+
|
| 98 |
+
gr.Markdown("""
|
| 99 |
+
Also called cougar or puma, this cat has a plain tawny or grayish coat without spots or rosettes. Its long tail and uniformly colored fur distinguish it from jaguars and ocelots.
|
| 100 |
+
|
| 101 |
+
----
|
| 102 |
+
|
| 103 |
+
## Common Eland
|
| 104 |
+
|
| 105 |
+
""")
|
| 106 |
+
|
| 107 |
+
gr.Image("species_id/commoneland.jpg", label="Eland example image", show_label=False)
|
| 108 |
+
|
| 109 |
+
gr.Markdown("""
|
| 110 |
+
The largest antelope species, with a robust body, spiraled horns on both sexes, and a characteristic dewlap hanging from the throat. It differs from waterbuck by its lighter tan coat, faint body stripes, and massive size.
|
| 111 |
+
|
| 112 |
+
----
|
| 113 |
+
|
| 114 |
+
## Waterbuck
|
| 115 |
+
""")
|
| 116 |
+
|
| 117 |
+
gr.Image("species_id/waterbuck.jpg", label="Waterbuck example image", show_label=False)
|
| 118 |
+
|
| 119 |
+
gr.Markdown("""
|
| 120 |
+
A shaggy, dark brown antelope recognized by its white rump ring and backward-curving horns in males. Smaller and darker than the common eland, waterbuck prefer wet habitats and lack the eland's throat dewlap.
|
| 121 |
+
|
| 122 |
+
----
|
| 123 |
+
|
| 124 |
+
""")
|
| 125 |
+
|
| 126 |
# load image metadata
|
| 127 |
images_data = []
|
| 128 |
for annotation in tqdm(data['annotations'], desc='Loading annotations'):
|
|
|
|
| 731 |
|
| 732 |
# Species guide content (initially hidden)
|
| 733 |
with gr.Column(visible=False) as species_guide_content:
|
| 734 |
+
create_species_guide_content()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 735 |
|
| 736 |
# Add spacing before buttons
|
| 737 |
gr.HTML("<div style='margin-top: 0.1em;'></div>")
|
|
|
|
| 792 |
[Placeholder]
|
| 793 |
""")
|
| 794 |
selection_help_close = gr.Button("Close", variant="secondary")
|
| 795 |
+
|
| 796 |
+
# Species guide popup during demo
|
| 797 |
+
with gr.Group(visible=False, elem_classes="popup-overlay") as species_guide_popup:
|
| 798 |
+
with gr.Group(elem_classes="popup-content"):
|
| 799 |
+
create_species_guide_content()
|
| 800 |
+
|
| 801 |
+
# Add spacing before button
|
| 802 |
+
gr.HTML("<div style='margin-top: 0.1em;'></div>")
|
| 803 |
+
|
| 804 |
+
species_guide_close = gr.Button("Go back to demo", variant="primary", size="lg")
|
| 805 |
|
| 806 |
# Two panels with bar charts
|
| 807 |
with gr.Row():
|
|
|
|
| 860 |
if DEBUG_MODE:
|
| 861 |
delete_button = gr.Button("ποΈ Delete Current Image", variant="stop", size="lg")
|
| 862 |
|
| 863 |
+
# Add buttons row
|
| 864 |
+
with gr.Row():
|
| 865 |
+
view_guide_button = gr.Button("π View Species Guide", variant="secondary", size="lg")
|
| 866 |
+
start_over_button = gr.Button("Start Over", variant="secondary", size="lg")
|
| 867 |
|
| 868 |
# Set up button interactions
|
| 869 |
def start_demo():
|
|
|
|
| 970 |
def hide_selection_help():
|
| 971 |
return gr.update(visible=False)
|
| 972 |
|
| 973 |
+
def show_species_guide_popup():
|
| 974 |
+
return gr.update(visible=True)
|
| 975 |
+
|
| 976 |
+
def hide_species_guide_popup():
|
| 977 |
+
return gr.update(visible=False)
|
| 978 |
+
|
| 979 |
popup_start_button.click(
|
| 980 |
fn=start_demo,
|
| 981 |
outputs=[image_display, status_with_help, model_predictions_display, prob_plot, accuracy_plot, popup_overlay, result_display, selection_help_button]
|
|
|
|
| 1027 |
outputs=[selection_help_popup]
|
| 1028 |
)
|
| 1029 |
|
| 1030 |
+
# Species guide popup handlers
|
| 1031 |
+
view_guide_button.click(
|
| 1032 |
+
fn=show_species_guide_popup,
|
| 1033 |
+
outputs=[species_guide_popup]
|
| 1034 |
+
)
|
| 1035 |
+
|
| 1036 |
+
species_guide_close.click(
|
| 1037 |
+
fn=hide_species_guide_popup,
|
| 1038 |
+
outputs=[species_guide_popup]
|
| 1039 |
+
)
|
| 1040 |
+
|
| 1041 |
for btn in species_buttons:
|
| 1042 |
btn.click(
|
| 1043 |
fn=check_answer,
|