FOL-Search commited on
Commit
3cb6bba
·
verified ·
1 Parent(s): 419da4f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +77 -77
app.py CHANGED
@@ -1,78 +1,78 @@
1
- import os
2
- import gradio as gr
3
- from PIL import Image
4
- from gradio_client import Client, handle_file
5
- import json
6
-
7
- BACKEND = os.getenv('BACEEND')
8
- TOKEN = os.getenv('TOKEN')
9
- backend = Client(BACKEND, hf_token=TOKEN)
10
-
11
- def search_image(file):
12
- result_text = backend.predict(
13
- file=handle_file(file),
14
- api_name="/search_image"
15
- )
16
-
17
- result = json.loads(result_text)
18
- outarray = []
19
- for item in result['result']:
20
- outarray.append((item['image'], item['url']))
21
- return outarray
22
-
23
- custom_css = """
24
- caption.caption {
25
- user-select: text;
26
- cursor: text;
27
- }
28
-
29
- div#component-18 {
30
- max-height: 63.39px;
31
- }
32
-
33
- .svelte-snayfm {
34
- height: auto;
35
- }
36
-
37
- .icon.svelte-snayfm {
38
- width: 48px;
39
- height: 48px;
40
- }
41
- """
42
-
43
- output = gr.Gallery(label="Found Images (The search may take a couple of minutes.)", columns=[3], object_fit="contain", height="480px", interactive=False)
44
- col2 = gr.Column(scale=2, visible=False)
45
-
46
- def init_ui():
47
- return gr.update(visible=True), gr.update(visible=False)
48
-
49
- def search_ui():
50
- return gr.update(visible=False), gr.update(visible=True)
51
-
52
- with gr.Blocks(css=custom_css, delete_cache=(3600, 3600)) as demo:
53
- gr.Markdown(
54
- """
55
- # Free Reverse Image Search
56
- ### [Learn more about our Reverse Image Search](https://faceonlive.com/reverse-image-search)
57
- <br/>
58
- """
59
- )
60
- with gr.Row():
61
- with gr.Column(scale=1) as col1:
62
- image = gr.Image(type='filepath', height=360)
63
- gr.HTML("<a href='https://faceonlive.com/face-search-online' target='_blank' style='font-size: 20px;'>Try Reverse Face Search Here</a>")
64
- search_image_button = gr.Button("Reverse Image Search")
65
-
66
- with col2.render():
67
- output.render()
68
- gr.HTML("<a href='https://faceonlive.com/face-search-online' target='_blank' style='font-size: 20px;'>Try Reverse Face Search Here</a>")
69
- new_search_button = gr.Button("🚀 Try New Search")
70
-
71
- search_image_button.click(search_ui, inputs=[], outputs=[col1, col2], api_name=False)
72
- search_image_button.click(search_image, inputs=[image], outputs=[output], api_name=False)
73
-
74
- new_search_button.click(init_ui, inputs=[], outputs=[col1, col2], api_name=False)
75
-
76
- gr.HTML('<a href="https://visitorbadge.io/status?path=https%3A%2F%2Fhuggingface.co%2Fspaces%2FReverseImageSearch%2FReverse-Image-Search"><img src="https://api.visitorbadge.io/api/visitors?path=https%3A%2F%2Fhuggingface.co%2Fspaces%2FReverseImageSearch%2FReverse-Image-Search&labelColor=%23ff8a65&countColor=%2337d67a&style=flat&labelStyle=upper" /></a>')
77
-
78
  demo.queue(api_open=False, default_concurrency_limit=8).launch(server_name="0.0.0.0", server_port=7860, show_api=False)
 
1
+ import os
2
+ import gradio as gr
3
+ from PIL import Image
4
+ from gradio_client import Client, handle_file
5
+ import json
6
+
7
+ BACKEND = os.getenv('BACKEND')
8
+ TOKEN = os.getenv('TOKEN')
9
+ backend = Client(BACKEND, hf_token=TOKEN)
10
+
11
+ def search_image(file):
12
+ result_text = backend.predict(
13
+ file=handle_file(file),
14
+ api_name="/search_image"
15
+ )
16
+
17
+ result = json.loads(result_text)
18
+ outarray = []
19
+ for item in result['result']:
20
+ outarray.append((item['image'], item['url']))
21
+ return outarray
22
+
23
+ custom_css = """
24
+ caption.caption {
25
+ user-select: text;
26
+ cursor: text;
27
+ }
28
+
29
+ div#component-18 {
30
+ max-height: 63.39px;
31
+ }
32
+
33
+ .svelte-snayfm {
34
+ height: auto;
35
+ }
36
+
37
+ .icon.svelte-snayfm {
38
+ width: 48px;
39
+ height: 48px;
40
+ }
41
+ """
42
+
43
+ output = gr.Gallery(label="Found Images (The search may take a couple of minutes.)", columns=[3], object_fit="contain", height="480px", interactive=False)
44
+ col2 = gr.Column(scale=2, visible=False)
45
+
46
+ def init_ui():
47
+ return gr.update(visible=True), gr.update(visible=False)
48
+
49
+ def search_ui():
50
+ return gr.update(visible=False), gr.update(visible=True)
51
+
52
+ with gr.Blocks(css=custom_css, delete_cache=(3600, 3600)) as demo:
53
+ gr.Markdown(
54
+ """
55
+ # Free Reverse Image Search
56
+ ### [Learn more about our Reverse Image Search](https://faceonlive.com/reverse-image-search)
57
+ <br/>
58
+ """
59
+ )
60
+ with gr.Row():
61
+ with gr.Column(scale=1) as col1:
62
+ image = gr.Image(type='filepath', height=360)
63
+ gr.HTML("<a href='https://faceonlive.com/face-search-online' target='_blank' style='font-size: 20px;'>Try Reverse Face Search Here</a>")
64
+ search_image_button = gr.Button("Reverse Image Search")
65
+
66
+ with col2.render():
67
+ output.render()
68
+ gr.HTML("<a href='https://faceonlive.com/face-search-online' target='_blank' style='font-size: 20px;'>Try Reverse Face Search Here</a>")
69
+ new_search_button = gr.Button("🚀 Try New Search")
70
+
71
+ search_image_button.click(search_ui, inputs=[], outputs=[col1, col2], api_name=False)
72
+ search_image_button.click(search_image, inputs=[image], outputs=[output], api_name=False)
73
+
74
+ new_search_button.click(init_ui, inputs=[], outputs=[col1, col2], api_name=False)
75
+
76
+ gr.HTML('<a href="https://visitorbadge.io/status?path=https%3A%2F%2Fhuggingface.co%2Fspaces%2FReverseImageSearch%2FReverse-Image-Search"><img src="https://api.visitorbadge.io/api/visitors?path=https%3A%2F%2Fhuggingface.co%2Fspaces%2FReverseImageSearch%2FReverse-Image-Search&labelColor=%23ff8a65&countColor=%2337d67a&style=flat&labelStyle=upper" /></a>')
77
+
78
  demo.queue(api_open=False, default_concurrency_limit=8).launch(server_name="0.0.0.0", server_port=7860, show_api=False)