msabia commited on
Commit
c5be32e
·
verified ·
1 Parent(s): ddbb835

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -22
app.py CHANGED
@@ -47,6 +47,7 @@ def searchEmbeddings(id, mod1, mod2):
47
  id = indx_to_id_dict[indx]
48
  id_list.append(id)
49
 
 
50
  image0 = get_image(dataset_image1, dataset_image2, dataset_image_mask, processid_to_index, original_indx)
51
  image1 = get_image(dataset_image1, dataset_image2, dataset_image_mask, processid_to_index, I[0][0])
52
  image2 = get_image(dataset_image1, dataset_image2, dataset_image_mask, processid_to_index, I[0][1])
@@ -59,20 +60,31 @@ def searchEmbeddings(id, mod1, mod2):
59
  image9 = get_image(dataset_image1, dataset_image2, dataset_image_mask, processid_to_index, I[0][8])
60
  image10 = get_image(dataset_image1, dataset_image2, dataset_image_mask, processid_to_index, I[0][9])
61
 
62
- return id_list, image0, image1, image2, image3, image4, image5, image6, image7, image8, image9, image10
 
 
 
 
 
 
 
 
 
 
 
 
 
63
 
64
  def getRandID():
65
  indx = random.randrange(0, 325667)
66
  return indx_to_id_dict[indx]
67
 
68
-
69
- # css = """
70
- # #image0 {
71
- # display: block;
72
- # margin-left: auto;
73
- # margin-right: auto;
74
- # }
75
- # """
76
 
77
  with gr.Blocks() as demo:
78
  # open general files
@@ -97,6 +109,11 @@ with gr.Blocks() as demo:
97
  with open("id_to_dna_emb_dict.pickle", "rb") as f:
98
  id_to_dna_emb_dict = pickle.load(f)
99
 
 
 
 
 
 
100
  with gr.Column():
101
  process_id = gr.Textbox(label="ID:", info="Enter a sample ID to search for")
102
  process_id_list = gr.Textbox(label="Closest 10 matches:" )
@@ -105,28 +122,54 @@ with gr.Blocks() as demo:
105
  search_btn = gr.Button("Search")
106
 
107
  with gr.Row():
108
- image0 = gr.Image(label="Original", height=550, elem_id="image0")
 
 
109
  with gr.Column():
110
  rand_id = gr.Textbox(label="Random ID:")
 
111
  id_btn = gr.Button("Get Random ID")
112
 
113
  with gr.Row():
114
- image1 = gr.Image(label=1)
115
- image2 = gr.Image(label=2)
116
- image3 = gr.Image(label=3)
117
- image4 = gr.Image(label=4)
118
- image5 = gr.Image(label=5)
119
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
  with gr.Row():
121
- image6 = gr.Image(label=6)
122
- image7 = gr.Image(label=7)
123
- image8 = gr.Image(label=8)
124
- image9 = gr.Image(label=9)
125
- image10 = gr.Image(label=10)
 
 
 
 
 
 
 
126
 
127
  id_btn.click(fn=getRandID, inputs=[], outputs=rand_id)
128
  search_btn.click(fn=searchEmbeddings, inputs=[process_id, mod1, mod2],
129
- outputs=[process_id_list, image0, image1, image2, image3, image4, image5, image6, image7, image8, image9, image10])
 
130
  examples = gr.Examples(
131
  examples=[["ABOTH966-22", "DNA", "DNA"],
132
  ["CRTOB8472-22", "DNA", "Image"],
 
47
  id = indx_to_id_dict[indx]
48
  id_list.append(id)
49
 
50
+ # get images
51
  image0 = get_image(dataset_image1, dataset_image2, dataset_image_mask, processid_to_index, original_indx)
52
  image1 = get_image(dataset_image1, dataset_image2, dataset_image_mask, processid_to_index, I[0][0])
53
  image2 = get_image(dataset_image1, dataset_image2, dataset_image_mask, processid_to_index, I[0][1])
 
60
  image9 = get_image(dataset_image1, dataset_image2, dataset_image_mask, processid_to_index, I[0][8])
61
  image10 = get_image(dataset_image1, dataset_image2, dataset_image_mask, processid_to_index, I[0][9])
62
 
63
+ # get taxonomic information
64
+ s0 = getTax(original_indx)
65
+ s1 = getTax(I[0][0])
66
+ s2 = getTax(I[0][1])
67
+ s3 = getTax(I[0][2])
68
+ s4 = getTax(I[0][3])
69
+ s5 = getTax(I[0][4])
70
+ s6 = getTax(I[0][5])
71
+ s7 = getTax(I[0][6])
72
+ s8 = getTax(I[0][7])
73
+ s9 = getTax(I[0][8])
74
+ s10 = getTax(I[0][9])
75
+
76
+ return id_list, image0, image1, image2, image3, image4, image5, image6, image7, image8, image9, image10, s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10
77
 
78
  def getRandID():
79
  indx = random.randrange(0, 325667)
80
  return indx_to_id_dict[indx]
81
 
82
+ def getTax(indx):
83
+ s = species[indx]
84
+ g = genus[indx]
85
+ f = family[indx]
86
+ str = "Species: " + s + "\nGenus: " + g + "\nFamily: " + f
87
+ return str
 
 
88
 
89
  with gr.Blocks() as demo:
90
  # open general files
 
109
  with open("id_to_dna_emb_dict.pickle", "rb") as f:
110
  id_to_dna_emb_dict = pickle.load(f)
111
 
112
+ # open taxonomy files
113
+ family = [item.decode("utf-8") for item in dataset_hdf5_all_key["family"][:]]
114
+ genus = [item.decode("utf-8") for item in dataset_hdf5_all_key["genus"][:]]
115
+ species = [item.decode("utf-8") for item in dataset_hdf5_all_key["species"][:]]
116
+
117
  with gr.Column():
118
  process_id = gr.Textbox(label="ID:", info="Enter a sample ID to search for")
119
  process_id_list = gr.Textbox(label="Closest 10 matches:" )
 
122
  search_btn = gr.Button("Search")
123
 
124
  with gr.Row():
125
+ with gr.Column():
126
+ image0 = gr.Image(label="Original", height=550)
127
+ tax0 = gr.Textbox(label="Taxonomy")
128
  with gr.Column():
129
  rand_id = gr.Textbox(label="Random ID:")
130
+ rand_id_indx = gr.Textbox(label="Index:")
131
  id_btn = gr.Button("Get Random ID")
132
 
133
  with gr.Row():
134
+ with gr.Column():
135
+ image1 = gr.Image(label=1)
136
+ tax1 = gr.Textbox(label="Taxonomy")
137
+ with gr.Column():
138
+ image2 = gr.Image(label=2)
139
+ tax2 = gr.Textbox(label="Taxonomy")
140
+ with gr.Column():
141
+ image3 = gr.Image(label=3)
142
+ tax3 = gr.Textbox(label="Taxonomy")
143
+
144
+ with gr.Row():
145
+ with gr.Column():
146
+ image4 = gr.Image(label=4)
147
+ tax4 = gr.Textbox(label="Taxonomy")
148
+ with gr.Column():
149
+ image5 = gr.Image(label=5)
150
+ tax5 = gr.Textbox(label="Taxonomy")
151
+ with gr.Column():
152
+ image6 = gr.Image(label=6)
153
+ tax6 = gr.Textbox(label="Taxonomy")
154
+
155
  with gr.Row():
156
+ with gr.Column():
157
+ image7 = gr.Image(label=7)
158
+ tax7 = gr.Textbox(label="Taxonomy")
159
+ with gr.Column():
160
+ image8 = gr.Image(label=8)
161
+ tax8 = gr.Textbox(label="Taxonomy")
162
+ with gr.Column():
163
+ image9 = gr.Image(label=9)
164
+ tax9 = gr.Textbox(label="Taxonomy")
165
+ with gr.Column():
166
+ image10 = gr.Image(label=10)
167
+ tax10 = gr.Textbox(label="Taxonomy")
168
 
169
  id_btn.click(fn=getRandID, inputs=[], outputs=rand_id)
170
  search_btn.click(fn=searchEmbeddings, inputs=[process_id, mod1, mod2],
171
+ outputs=[process_id_list, image0, image1, image2, image3, image4, image5, image6, image7, image8, image9, image10,
172
+ tax0, tax1, tax2, tax3, tax4, tax5, tax6, tax7, tax8, tax9, tax10])
173
  examples = gr.Examples(
174
  examples=[["ABOTH966-22", "DNA", "DNA"],
175
  ["CRTOB8472-22", "DNA", "Image"],