text and link
Browse files
app.py
CHANGED
|
@@ -18,7 +18,6 @@ else:
|
|
| 18 |
model = OwlViTForObjectDetection.from_pretrained("google/owlvit-large-patch14").to(device)
|
| 19 |
model.eval()
|
| 20 |
processor = OwlViTProcessor.from_pretrained("google/owlvit-large-patch14")
|
| 21 |
-
print(os.listdir())
|
| 22 |
|
| 23 |
def query_image(img, text_queries, score_threshold):
|
| 24 |
text_queries = text_queries.split(",")
|
|
@@ -64,11 +63,12 @@ with gr.Blocks() as demo:
|
|
| 64 |
with gr.Row():
|
| 65 |
with gr.Column():
|
| 66 |
|
| 67 |
-
gr.Markdown("""Insert an image
|
|
|
|
| 68 |
inputf1 = gr.Image(source="upload")
|
| 69 |
inputf2 = gr.Textbox()
|
| 70 |
gr.Markdown("""
|
| 71 |
-
\n You can also use the score threshold slider to set a threshold to filter out
|
| 72 |
""")
|
| 73 |
inputf3 = gr.Slider(0, 1, value=0.1)
|
| 74 |
|
|
@@ -80,9 +80,13 @@ with gr.Blocks() as demo:
|
|
| 80 |
with gr.Tab("Capture image with webcam"):
|
| 81 |
with gr.Row():
|
| 82 |
with gr.Column():
|
| 83 |
-
|
|
|
|
| 84 |
inputweb1 = gr.Image(source="webcam")
|
| 85 |
inputweb2 = gr.Textbox()
|
|
|
|
|
|
|
|
|
|
| 86 |
inputweb3 = gr.Slider(0, 1, value=0.1)
|
| 87 |
|
| 88 |
inputs_web = [inputweb1, inputweb2, inputweb3]
|
|
@@ -90,8 +94,8 @@ with gr.Blocks() as demo:
|
|
| 90 |
|
| 91 |
web_output = gr.Image()
|
| 92 |
|
| 93 |
-
submit_btn.click(fn=query_image, inputs= inputs_file, outputs = im_output)
|
| 94 |
-
submit_btn_web.click(fn=query_image, inputs= inputs_web, outputs = web_output)
|
| 95 |
|
| 96 |
#gr.Markdown("## Image Examples")
|
| 97 |
#examples= [os.path.join(os.path.dirname(__file__), "IMGP0178.jpg")]
|
|
@@ -101,5 +105,11 @@ with gr.Blocks() as demo:
|
|
| 101 |
# outputs=[im_output],
|
| 102 |
# fn=query_image
|
| 103 |
# )
|
| 104 |
-
|
| 105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
model = OwlViTForObjectDetection.from_pretrained("google/owlvit-large-patch14").to(device)
|
| 19 |
model.eval()
|
| 20 |
processor = OwlViTProcessor.from_pretrained("google/owlvit-large-patch14")
|
|
|
|
| 21 |
|
| 22 |
def query_image(img, text_queries, score_threshold):
|
| 23 |
text_queries = text_queries.split(",")
|
|
|
|
| 63 |
with gr.Row():
|
| 64 |
with gr.Column():
|
| 65 |
|
| 66 |
+
gr.Markdown("""Insert an image below and add text descriptions of what you are looking for.
|
| 67 |
+
If you wish for assistance to find the right text queries you can ask for help from [ChatBRD](https://chatbrd.novonordisk.com/#/) but remember you need to log on novos VPN before you can use it.""")
|
| 68 |
inputf1 = gr.Image(source="upload")
|
| 69 |
inputf2 = gr.Textbox()
|
| 70 |
gr.Markdown("""
|
| 71 |
+
\n You can also use the score threshold slider to set a threshold to filter out lower probability predictions.
|
| 72 |
""")
|
| 73 |
inputf3 = gr.Slider(0, 1, value=0.1)
|
| 74 |
|
|
|
|
| 80 |
with gr.Tab("Capture image with webcam"):
|
| 81 |
with gr.Row():
|
| 82 |
with gr.Column():
|
| 83 |
+
gr.Markdown("""Insert an image below and add text descriptions of what you are looking for.
|
| 84 |
+
If you wish for assistance to find the right text queries you can ask for help from [ChatBRD](https://chatbrd.novonordisk.com/#/) but remember you need to log on novos VPN before you can use it.""")
|
| 85 |
inputweb1 = gr.Image(source="webcam")
|
| 86 |
inputweb2 = gr.Textbox()
|
| 87 |
+
gr.Markdown("""
|
| 88 |
+
\n You can also use the score threshold slider to set a threshold to filter out lower probability predictions.
|
| 89 |
+
""")
|
| 90 |
inputweb3 = gr.Slider(0, 1, value=0.1)
|
| 91 |
|
| 92 |
inputs_web = [inputweb1, inputweb2, inputweb3]
|
|
|
|
| 94 |
|
| 95 |
web_output = gr.Image()
|
| 96 |
|
| 97 |
+
submit_btn.click(fn=query_image, inputs= inputs_file, outputs = im_output, queue=True)
|
| 98 |
+
submit_btn_web.click(fn=query_image, inputs= inputs_web, outputs = web_output, queue=True)
|
| 99 |
|
| 100 |
#gr.Markdown("## Image Examples")
|
| 101 |
#examples= [os.path.join(os.path.dirname(__file__), "IMGP0178.jpg")]
|
|
|
|
| 105 |
# outputs=[im_output],
|
| 106 |
# fn=query_image
|
| 107 |
# )
|
| 108 |
+
if __name__ == "__main__":
|
| 109 |
+
|
| 110 |
+
demo.queue(
|
| 111 |
+
concurrency_count=40, # When you increase the concurrency_count parameter in queue(), max_threads() in launch() is automatically increased as well.
|
| 112 |
+
max_size=25, # Maximum number of requests that the queue processes
|
| 113 |
+
api_open = False # When creating a Gradio demo, you may want to restrict all traffic to happen through the user interface as opposed to the programmatic API that is automatically created for your Gradio demo.
|
| 114 |
+
)
|
| 115 |
+
demo.launch(auth=("novouser", "bstad2023"))
|