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