Spaces:
Runtime error
Runtime error
henryhyunwookim
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,51 +1,52 @@
|
|
1 |
-
from utils.utils import get_logger, initialization, get_result
|
2 |
-
import gradio as gr
|
3 |
-
import logging
|
4 |
-
|
5 |
-
|
6 |
-
logger = get_logger()
|
7 |
-
collection = None
|
8 |
-
|
9 |
-
|
10 |
-
def main(query):
|
11 |
-
logger = logging.getLogger(__name__)
|
12 |
-
print("Starting search...")
|
13 |
-
logger.info("Starting search...")
|
14 |
-
print("-------------------------------------------------------")
|
15 |
-
logger.info("-------------------------------------------------------")
|
16 |
-
exit = False
|
17 |
-
while not exit:
|
18 |
-
# Collect user query
|
19 |
-
# query = input('Type your query, or "exit" if you want to exit: ')
|
20 |
-
|
21 |
-
if query == "exit":
|
22 |
-
exit = True
|
23 |
-
print("-------------------------------------------------------")
|
24 |
-
logger.info("-------------------------------------------------------")
|
25 |
-
print("Search terminated.")
|
26 |
-
logger.info("Search terminated.")
|
27 |
-
return None, "Search terminated."
|
28 |
-
else:
|
29 |
-
# Get search result including the original descriptions of the images
|
30 |
-
image, text = get_result(collection, data_set, query, model, n_results=2)
|
31 |
-
|
32 |
-
# Display the image, its caption, and user query
|
33 |
-
# show_image(image, text, query)
|
34 |
-
return image, text
|
35 |
-
|
36 |
-
|
37 |
-
if __name__ == "__main__":
|
38 |
-
try:
|
39 |
-
if collection == None:
|
40 |
-
collection, data_set, model, logger = initialization(logger)
|
41 |
-
# main()
|
42 |
-
app = gr.Interface(
|
43 |
-
fn=main,
|
44 |
-
inputs=["
|
45 |
-
outputs=["
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
|
|
51 |
raise e
|
|
|
1 |
+
from utils.utils import get_logger, initialization, get_result
|
2 |
+
import gradio as gr
|
3 |
+
import logging
|
4 |
+
|
5 |
+
|
6 |
+
logger = get_logger()
|
7 |
+
collection = None
|
8 |
+
|
9 |
+
|
10 |
+
def main(query):
|
11 |
+
logger = logging.getLogger(__name__)
|
12 |
+
print("Starting search...")
|
13 |
+
logger.info("Starting search...")
|
14 |
+
print("-------------------------------------------------------")
|
15 |
+
logger.info("-------------------------------------------------------")
|
16 |
+
exit = False
|
17 |
+
while not exit:
|
18 |
+
# Collect user query
|
19 |
+
# query = input('Type your query, or "exit" if you want to exit: ')
|
20 |
+
|
21 |
+
if query == "exit":
|
22 |
+
exit = True
|
23 |
+
print("-------------------------------------------------------")
|
24 |
+
logger.info("-------------------------------------------------------")
|
25 |
+
print("Search terminated.")
|
26 |
+
logger.info("Search terminated.")
|
27 |
+
return None, "Search terminated."
|
28 |
+
else:
|
29 |
+
# Get search result including the original descriptions of the images
|
30 |
+
image, text = get_result(collection, data_set, query, model, n_results=2)
|
31 |
+
|
32 |
+
# Display the image, its caption, and user query
|
33 |
+
# show_image(image, text, query)
|
34 |
+
return image, text
|
35 |
+
|
36 |
+
|
37 |
+
if __name__ == "__main__":
|
38 |
+
try:
|
39 |
+
if collection == None:
|
40 |
+
collection, data_set, model, logger = initialization(logger)
|
41 |
+
# main()
|
42 |
+
app = gr.Interface(
|
43 |
+
fn=main,
|
44 |
+
inputs=[gr.Textbox(label="Describe the scene that you are looking for:")],
|
45 |
+
outputs=[gr.Image(label="Here's the scene found based on your description:"),
|
46 |
+
gr.Textbox(label="Origina description of the found scene:")],
|
47 |
+
title="Search for a scene in the world of GTA!"
|
48 |
+
)
|
49 |
+
app.launch(share=True)
|
50 |
+
except Exception as e:
|
51 |
+
logger.exception(e)
|
52 |
raise e
|