Samuel Schmidt commited on
Commit
0ab69ad
·
1 Parent(s): 0cbab2a

Add: Switch from gradio interface to demo for adding re-index button

Browse files
Files changed (1) hide show
  1. src/app.py +19 -2
src/app.py CHANGED
@@ -8,7 +8,7 @@ from datasets import *
8
  dataset = load_dataset("huggan/CelebA-faces")
9
  candidate_subset = dataset["train"].select(range(1000)) # This is a small CBIR app! :D
10
 
11
- def emb_dataset(dataset):
12
  # This function might need to be split up, to reduce start-up time of app
13
  # It could also use batches to increase speed
14
  # If indexes are saved in files, this is all not really necessary
@@ -29,7 +29,7 @@ def emb_dataset(dataset):
29
  print(dataset_with_embeddings)
30
  return dataset_with_embeddings
31
 
32
- dataset_with_embeddings = emb_dataset(candidate_subset)
33
 
34
  # Main function, to find similar images
35
  # TODO: implement different distance measures
@@ -81,3 +81,20 @@ iface = gr.Interface(
81
 
82
  # Launch the Gradio interface
83
  iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  dataset = load_dataset("huggan/CelebA-faces")
9
  candidate_subset = dataset["train"].select(range(1000)) # This is a small CBIR app! :D
10
 
11
+ def index_dataset(dataset):
12
  # This function might need to be split up, to reduce start-up time of app
13
  # It could also use batches to increase speed
14
  # If indexes are saved in files, this is all not really necessary
 
29
  print(dataset_with_embeddings)
30
  return dataset_with_embeddings
31
 
32
+ dataset_with_embeddings = index_dataset(candidate_subset)
33
 
34
  # Main function, to find similar images
35
  # TODO: implement different distance measures
 
81
 
82
  # Launch the Gradio interface
83
  iface.launch()
84
+
85
+ with gr.Blocks() as demo:
86
+ image_input = gr.Image(type="pil", label="Please upload an image")
87
+ checkboxes_descr = gr.CheckboxGroup(["Color Descriptor", "LBP", "CLIP"], label="Please choose an descriptor"))
88
+
89
+ btn = gr.Button(value="Submit")
90
+ gallery_output = gr.Gallery()
91
+
92
+ btn.click(get_neighbors,
93
+ inputs=[image_input, checkboxes_descr],
94
+ outputs=[gallery_output]
95
+ )
96
+ btn_index = gr.Button(value="Re-index Dataset")
97
+ btn.click(index_dataset)
98
+
99
+ if __name__ == "__main__":
100
+ demo.launch()