omerXfaruq commited on
Commit
a193d64
1 Parent(s): b2f105a
Files changed (2) hide show
  1. README.md +1 -1
  2. app.py +21 -14
README.md CHANGED
@@ -1,5 +1,5 @@
1
  ---
2
- title: FindYourSiblings
3
  emoji: 📉
4
  colorFrom: green
5
  colorTo: red
 
1
  ---
2
+ title: FindYourTwins
3
  emoji: 📉
4
  colorFrom: green
5
  colorTo: red
app.py CHANGED
@@ -16,7 +16,7 @@ with gr.Blocks() as demo:
16
  """
17
  # Find Your Twins
18
 
19
- Upload your face and find the most similar people from [Face Aging Dataset](https://huggingface.co/datasets/BounharAbdelaziz/Face-Aging-Dataset) using Google's [VIT](https://huggingface.co/google/vit-base-patch16-224-in21k) model. The task of finding most similar vectors is powered by [Upstash Vector](https://upstash.com) 🚀. Check our blog post *here*.
20
  """
21
  )
22
 
@@ -25,10 +25,9 @@ with gr.Blocks() as demo:
25
  with gr.Column(scale=1):
26
  input_image = gr.Image(type="pil")
27
  with gr.Column(scale=2):
28
- output_image = gr.Gallery(height=450)
29
 
30
-
31
- @input_image.change(inputs=input_image, outputs=output_image)
32
  async def find_similar_faces(image):
33
  if image is None:
34
  return None
@@ -38,11 +37,14 @@ with gr.Blocks() as demo:
38
  result = await index.query(vector=embed.tolist(), top_k=4)
39
  return [dataset["train"][int(vector.id)]["image"] for vector in result]
40
 
41
-
42
  gr.Examples(
43
- examples=[dataset["train"][6]["image"], dataset["train"][7]["image"], dataset["train"][8]["image"]],
 
 
 
 
44
  inputs=input_image,
45
- outputs=output_image,
46
  fn=find_similar_faces,
47
  cache_examples=False,
48
  )
@@ -51,26 +53,31 @@ with gr.Blocks() as demo:
51
  with gr.Row():
52
  with gr.Column(scale=1):
53
  adv_input_image = gr.Image(type="pil")
54
- adv_image_count = gr.Number(9, label="Image Count")
55
  adv_button = gr.Button("Submit")
56
 
57
  with gr.Column(scale=2):
58
  adv_output_image = gr.Gallery()
59
 
60
-
61
- @adv_button.click(inputs=[adv_input_image, adv_image_count], outputs=[adv_output_image])
62
  async def find_similar_faces(image, count):
63
  inputs = extractor(images=image, return_tensors="pt")
64
  outputs = model(**inputs)
65
  embed = outputs.last_hidden_state[0][0]
66
  result = await index.query(
67
- vector=embed.tolist(), top_k=max(1, min(19, count))
68
  )
69
  return [dataset["train"][int(vector.id)]["image"] for vector in result]
70
 
71
-
72
- adv_input_image.upload(fn=find_similar_faces, inputs=[adv_input_image, adv_image_count],
73
- outputs=[adv_output_image])
 
 
 
 
 
 
 
74
 
75
  if __name__ == "__main__":
76
  demo.launch(debug=True, share=True)
 
16
  """
17
  # Find Your Twins
18
 
19
+ Upload your face and find the most similar faces from [Face Aging Dataset](https://huggingface.co/datasets/BounharAbdelaziz/Face-Aging-Dataset) using Google's [VIT](https://huggingface.co/google/vit-base-patch16-224-in21k) model. For best results please use 1x1 ratio face images, take a look at examples. The Vector similarity search is powered by [Upstash Vector](https://upstash.com) 🚀. You can check our blog *post* to learn more.
20
  """
21
  )
22
 
 
25
  with gr.Column(scale=1):
26
  input_image = gr.Image(type="pil")
27
  with gr.Column(scale=2):
28
+ output_images = gr.Gallery()
29
 
30
+ @input_image.change(inputs=input_image, outputs=output_images)
 
31
  async def find_similar_faces(image):
32
  if image is None:
33
  return None
 
37
  result = await index.query(vector=embed.tolist(), top_k=4)
38
  return [dataset["train"][int(vector.id)]["image"] for vector in result]
39
 
 
40
  gr.Examples(
41
+ examples=[
42
+ dataset["train"][6]["image"],
43
+ dataset["train"][7]["image"],
44
+ dataset["train"][8]["image"],
45
+ ],
46
  inputs=input_image,
47
+ outputs=output_images,
48
  fn=find_similar_faces,
49
  cache_examples=False,
50
  )
 
53
  with gr.Row():
54
  with gr.Column(scale=1):
55
  adv_input_image = gr.Image(type="pil")
56
+ adv_image_count = gr.Slider(1, 30, 10, label="Image Count")
57
  adv_button = gr.Button("Submit")
58
 
59
  with gr.Column(scale=2):
60
  adv_output_image = gr.Gallery()
61
 
 
 
62
  async def find_similar_faces(image, count):
63
  inputs = extractor(images=image, return_tensors="pt")
64
  outputs = model(**inputs)
65
  embed = outputs.last_hidden_state[0][0]
66
  result = await index.query(
67
+ vector=embed.tolist(), top_k=max(1, min(30, count))
68
  )
69
  return [dataset["train"][int(vector.id)]["image"] for vector in result]
70
 
71
+ adv_button.click(
72
+ fn=find_similar_faces,
73
+ inputs=[adv_input_image, adv_image_count],
74
+ outputs=[adv_output_image],
75
+ )
76
+ adv_input_image.upload(
77
+ fn=find_similar_faces,
78
+ inputs=[adv_input_image, adv_image_count],
79
+ outputs=[adv_output_image],
80
+ )
81
 
82
  if __name__ == "__main__":
83
  demo.launch(debug=True, share=True)