Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -7,8 +7,16 @@ import json
|
|
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"
|
@@ -38,6 +46,34 @@ div#component-18 {
|
|
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)
|
@@ -49,30 +85,35 @@ def init_ui():
|
|
49 |
def search_ui():
|
50 |
return gr.update(visible=False), gr.update(visible=True)
|
51 |
|
52 |
-
|
53 |
-
|
54 |
-
"""
|
55 |
-
# Free Reverse Image Search
|
56 |
### [Learn more about our Reverse Image Search](https://faceonlive.com/reverse-image-search)
|
57 |
-
|
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("<
|
64 |
-
|
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)
|
|
|
7 |
BACKEND = os.getenv('BACKEND')
|
8 |
TOKEN = os.getenv('TOKEN')
|
9 |
backend = Client(BACKEND, hf_token=TOKEN)
|
10 |
+
JS_FUNC1 = os.getenv("JS_FUNC1")
|
11 |
+
JS_FUNC2 = os.getenv("JS_FUNC2")
|
12 |
|
13 |
def search_image(file):
|
14 |
+
try:
|
15 |
+
handle_file(file)
|
16 |
+
except Exception as e:
|
17 |
+
gr.Info("Please upload an image file.")
|
18 |
+
return []
|
19 |
+
|
20 |
result_text = backend.predict(
|
21 |
file=handle_file(file),
|
22 |
api_name="/search_image"
|
|
|
46 |
width: 48px;
|
47 |
height: 48px;
|
48 |
}
|
49 |
+
|
50 |
+
.button-gradient {
|
51 |
+
background: linear-gradient(45deg, #ff416c, #ff4b2b, #ff9b00, #ff416c);
|
52 |
+
background-size: 400% 400%;
|
53 |
+
border: none;
|
54 |
+
padding: 14px 28px;
|
55 |
+
font-size: 16px;
|
56 |
+
font-weight: bold;
|
57 |
+
color: white;
|
58 |
+
border-radius: 10px;
|
59 |
+
cursor: pointer;
|
60 |
+
transition: 0.3s ease-in-out;
|
61 |
+
animation: gradientAnimation 2s infinite linear;
|
62 |
+
box-shadow: 0 4px 10px rgba(255, 65, 108, 0.6);
|
63 |
+
}
|
64 |
+
|
65 |
+
@keyframes gradientAnimation {
|
66 |
+
0% { background-position: 0% 50%; }
|
67 |
+
25% { background-position: 50% 100%; }
|
68 |
+
50% { background-position: 100% 50%; }
|
69 |
+
75% { background-position: 50% 0%; }
|
70 |
+
100% { background-position: 0% 50%; }
|
71 |
+
}
|
72 |
+
|
73 |
+
.button-gradient:hover {
|
74 |
+
transform: scale(1.05);
|
75 |
+
box-shadow: 0 6px 15px rgba(255, 75, 43, 0.8);
|
76 |
+
}
|
77 |
"""
|
78 |
|
79 |
output = gr.Gallery(label="Found Images (The search may take a couple of minutes.)", columns=[3], object_fit="contain", height="480px", interactive=False)
|
|
|
85 |
def search_ui():
|
86 |
return gr.update(visible=False), gr.update(visible=True)
|
87 |
|
88 |
+
MARKDOWN0 = """
|
89 |
+
# Free Reverse Image Search - ❤️Like above if this space helps
|
|
|
|
|
90 |
### [Learn more about our Reverse Image Search](https://faceonlive.com/reverse-image-search)
|
91 |
+
"""
|
92 |
+
MARKDOWN3 = """
|
93 |
+
<div align="right"><a href="https://faceonlive.com/face-search-online" target='_blank' style='font-size: 16px;'>Reverse Face Search</div><br/>
|
94 |
+
<div align="right"><a href="https://faceonlive.com/deepfake-detector" target='_blank' style='font-size: 16px;'>AI Generated Image & Deepfake Detector</div>
|
95 |
+
"""
|
96 |
+
|
97 |
+
with gr.Blocks(css=custom_css, delete_cache=(3600, 3600)) as demo:
|
98 |
+
gr.Markdown(MARKDOWN0)
|
99 |
with gr.Row():
|
100 |
with gr.Column(scale=1) as col1:
|
101 |
image = gr.Image(type='filepath', height=360)
|
102 |
+
gr.HTML("<div id='limit'></div>")
|
103 |
+
limit_button = gr.Button("🔍 Reverse Image Search", elem_classes="button-gradient")
|
104 |
+
search_image_button = gr.Button("Reverse Image Search", visible=False, elem_id="submit_btn")
|
105 |
+
gr.HTML(MARKDOWN3)
|
106 |
with col2.render():
|
107 |
output.render()
|
|
|
108 |
new_search_button = gr.Button("🚀 Try New Search")
|
109 |
+
gr.HTML(MARKDOWN3)
|
110 |
|
111 |
+
limit_button.click(None, js=JS_FUNC2)
|
112 |
+
demo.load(None, inputs=None, outputs=None, js=JS_FUNC1)
|
113 |
search_image_button.click(search_ui, inputs=[], outputs=[col1, col2], api_name=False)
|
114 |
search_image_button.click(search_image, inputs=[image], outputs=[output], api_name=False)
|
115 |
|
116 |
new_search_button.click(init_ui, inputs=[], outputs=[col1, col2], api_name=False)
|
|
|
117 |
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>')
|
118 |
|
119 |
demo.queue(api_open=False, default_concurrency_limit=8).launch(server_name="0.0.0.0", server_port=7860, show_api=False)
|