osanchik commited on
Commit
d760786
·
1 Parent(s): 1cbcc67

removed Find1 button

Browse files
Files changed (2) hide show
  1. app.py +6 -17
  2. main.py +2 -25
app.py CHANGED
@@ -6,13 +6,13 @@ from setup import *
6
  from PIL import Image
7
  import time
8
 
9
- thumbnail_width = 300
10
  def show_result(search_request,
11
  search_result,
12
  img_dir,
13
  container,
14
  search_time) :
15
 
 
16
  container.header("It took me "+ "{:.2f}".format(search_time)+ " sec to find \"" +search_request+ "\" for you !")
17
  i = 0
18
  for _ in range(0, 3):
@@ -53,23 +53,12 @@ def show_landing() :
53
  'Search ...')
54
 
55
 
56
- col1, col2, col3 = st.columns(3)
57
 
58
- if col1.button('Find Release 1!') and os.path.exists('img'):
59
  results = st.container()
60
  start_time = time.time()
61
- search_result = search1(search_request)
62
- end_time = time.time()
63
- show_result(search_request,
64
- search_result,
65
- 'img/',
66
- results,
67
- end_time - start_time)
68
-
69
- if col2.button('Find Release 2!') and os.path.exists(IMAGE_DIR) :
70
- results = st.container()
71
- start_time = time.time()
72
- search_result = search2(search_request)
73
  end_time = time.time()
74
  show_result(search_request,
75
  search_result,
@@ -77,10 +66,10 @@ def show_landing() :
77
  results,
78
  end_time - start_time)
79
 
80
- if col3.button('Find Release 3!') and os.path.exists(IMAGE_DIR) :
81
  results = st.container()
82
  start_time = time.time()
83
- search_result = search3(search_request)
84
  end_time = time.time()
85
  show_result(search_request,
86
  search_result,
 
6
  from PIL import Image
7
  import time
8
 
 
9
  def show_result(search_request,
10
  search_result,
11
  img_dir,
12
  container,
13
  search_time) :
14
 
15
+ thumbnail_width = 300
16
  container.header("It took me "+ "{:.2f}".format(search_time)+ " sec to find \"" +search_request+ "\" for you !")
17
  i = 0
18
  for _ in range(0, 3):
 
53
  'Search ...')
54
 
55
 
56
+ col1, col2 = st.columns(2)
57
 
58
+ if col1.button('Find!') and os.path.exists(IMAGE_DIR) :
59
  results = st.container()
60
  start_time = time.time()
61
+ search_result = search(search_request)
 
 
 
 
 
 
 
 
 
 
 
62
  end_time = time.time()
63
  show_result(search_request,
64
  search_result,
 
66
  results,
67
  end_time - start_time)
68
 
69
+ if col2.button('Find with faiss!') and os.path.exists(IMAGE_DIR) :
70
  results = st.container()
71
  start_time = time.time()
72
+ search_result = searchWithFaiss(search_request)
73
  end_time = time.time()
74
  show_result(search_request,
75
  search_result,
main.py CHANGED
@@ -4,30 +4,7 @@ from dataframe import *
4
  from model import *
5
 
6
 
7
- images = ["Girl.jpg",
8
- "Cat In Hat.jpg",
9
- "Cat In The Hat.jpg",
10
- "Fox In Socks.jpg",
11
- "Green Eggs And Ham.jpg",
12
- "Green Eggs with Ham.jpg",
13
- "Grinch.jpg",
14
- "Horton.jpg",
15
- "Lorax.jpg",
16
- "Thing1 and Thing2.jpg",
17
- "Turtle.jpg",
18
- "One Fish.jpg",
19
- "Two Fish.jpg"]
20
-
21
-
22
-
23
- def search1(search_prompt : str):
24
- """
25
- Given a search_prompt, return an array of pictures to display
26
- """
27
-
28
- return [ (images[i], images[i].split('.')[0], '') for i in random.sample(range(len(images)), 4) ]
29
-
30
- def search2(search_prompt : str) :
31
 
32
  # Set the device
33
  device = "cuda" if torch.cuda.is_available() else "cpu"
@@ -46,7 +23,7 @@ def search2(search_prompt : str) :
46
  device = device,
47
  top_K=4)
48
 
49
- def search3(search_prompt : str) :
50
 
51
  # Set the device
52
  device = "cuda" if torch.cuda.is_available() else "cpu"
 
4
  from model import *
5
 
6
 
7
+ def search(search_prompt : str) :
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
  # Set the device
10
  device = "cuda" if torch.cuda.is_available() else "cpu"
 
23
  device = device,
24
  top_K=4)
25
 
26
+ def searchWithFaiss(search_prompt : str) :
27
 
28
  # Set the device
29
  device = "cuda" if torch.cuda.is_available() else "cpu"