Spaces:
Running
Running
Darius Morawiec
commited on
Commit
·
27781ba
1
Parent(s):
071cb82
chore: Update UI
Browse files
app.py
CHANGED
|
@@ -3,7 +3,10 @@ import PIL.Image
|
|
| 3 |
import torch
|
| 4 |
from transformers import AutoModelForZeroShotObjectDetection, AutoProcessor
|
| 5 |
|
|
|
|
|
|
|
| 6 |
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
|
|
|
| 7 |
|
| 8 |
|
| 9 |
class Detector:
|
|
@@ -64,7 +67,7 @@ def _postprocess(detections):
|
|
| 64 |
return annotations
|
| 65 |
|
| 66 |
|
| 67 |
-
def
|
| 68 |
labels = [label.strip() for label in labels.split(",")]
|
| 69 |
|
| 70 |
detections = []
|
|
@@ -79,10 +82,8 @@ def detect_objects(image, labels, confidence_threshold):
|
|
| 79 |
return tuple((image, det) for det in detections)
|
| 80 |
|
| 81 |
|
| 82 |
-
with gr.Blocks(delete_cache=(5, 10)) as demo:
|
| 83 |
-
gr.Markdown(
|
| 84 |
-
"# LLMDet Arena ✨\n ### [Paper](https://arxiv.org/abs/2501.18954) - [Repository](https://github.com/iSEE-Laboratory/LLMDet)"
|
| 85 |
-
)
|
| 86 |
|
| 87 |
with gr.Row():
|
| 88 |
with gr.Column():
|
|
@@ -111,7 +112,7 @@ with gr.Blocks(delete_cache=(5, 10)) as demo:
|
|
| 111 |
)
|
| 112 |
|
| 113 |
with gr.Row():
|
| 114 |
-
detect_button = gr.Button("
|
| 115 |
|
| 116 |
with gr.Row():
|
| 117 |
gr.Markdown("## Output Annotated Images")
|
|
@@ -123,7 +124,7 @@ with gr.Blocks(delete_cache=(5, 10)) as demo:
|
|
| 123 |
|
| 124 |
# Connect the button to the detection function
|
| 125 |
detect_button.click(
|
| 126 |
-
fn=
|
| 127 |
inputs=[image_input, text_input, confidence_slider],
|
| 128 |
outputs=[
|
| 129 |
output_annotated_image_tiny,
|
|
@@ -160,10 +161,14 @@ with gr.Blocks(delete_cache=(5, 10)) as demo:
|
|
| 160 |
output_annotated_image_base,
|
| 161 |
output_annotated_image_large,
|
| 162 |
],
|
| 163 |
-
fn=
|
| 164 |
cache_examples=True,
|
| 165 |
)
|
| 166 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 167 |
|
| 168 |
if __name__ == "__main__":
|
| 169 |
demo.launch()
|
|
|
|
| 3 |
import torch
|
| 4 |
from transformers import AutoModelForZeroShotObjectDetection, AutoProcessor
|
| 5 |
|
| 6 |
+
from kofi import SCRIPT
|
| 7 |
+
|
| 8 |
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
| 9 |
+
HEADLINE = "# [LLMDet](https://github.com/iSEE-Laboratory/LLMDet) Arena ✨"
|
| 10 |
|
| 11 |
|
| 12 |
class Detector:
|
|
|
|
| 67 |
return annotations
|
| 68 |
|
| 69 |
|
| 70 |
+
def run(image, labels, confidence_threshold):
|
| 71 |
labels = [label.strip() for label in labels.split(",")]
|
| 72 |
|
| 73 |
detections = []
|
|
|
|
| 82 |
return tuple((image, det) for det in detections)
|
| 83 |
|
| 84 |
|
| 85 |
+
with gr.Blocks(delete_cache=(5, 10), js=SCRIPT) as demo:
|
| 86 |
+
gr.Markdown(HEADLINE)
|
|
|
|
|
|
|
| 87 |
|
| 88 |
with gr.Row():
|
| 89 |
with gr.Column():
|
|
|
|
| 112 |
)
|
| 113 |
|
| 114 |
with gr.Row():
|
| 115 |
+
detect_button = gr.Button("Run")
|
| 116 |
|
| 117 |
with gr.Row():
|
| 118 |
gr.Markdown("## Output Annotated Images")
|
|
|
|
| 124 |
|
| 125 |
# Connect the button to the detection function
|
| 126 |
detect_button.click(
|
| 127 |
+
fn=run,
|
| 128 |
inputs=[image_input, text_input, confidence_slider],
|
| 129 |
outputs=[
|
| 130 |
output_annotated_image_tiny,
|
|
|
|
| 161 |
output_annotated_image_base,
|
| 162 |
output_annotated_image_large,
|
| 163 |
],
|
| 164 |
+
fn=run,
|
| 165 |
cache_examples=True,
|
| 166 |
)
|
| 167 |
|
| 168 |
+
with gr.Row():
|
| 169 |
+
with gr.Column():
|
| 170 |
+
gr.HTML('<div id="kofi" style="text-align: center;"></div>')
|
| 171 |
+
|
| 172 |
|
| 173 |
if __name__ == "__main__":
|
| 174 |
demo.launch()
|
kofi.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
SCRIPT = """
|
| 2 |
+
async function loadKofi() {
|
| 3 |
+
var kofiwidget2 = kofiwidget2 ||
|
| 4 |
+
(function () {
|
| 5 |
+
var style = "";
|
| 6 |
+
var html = "";
|
| 7 |
+
var color = "";
|
| 8 |
+
var text = "";
|
| 9 |
+
var id = "";
|
| 10 |
+
return {
|
| 11 |
+
init: function (pText, pColor, pId) {
|
| 12 |
+
color = pColor;
|
| 13 |
+
text = pText;
|
| 14 |
+
id = pId;
|
| 15 |
+
style =
|
| 16 |
+
"img.kofiimg{display: initial!important;vertical-align:middle;height:13px!important;width:20px!important;padding-top:0!important;padding-bottom:0!important;border:none;margin-top:0;margin-right:7px!important;margin-left:0!important;margin-bottom:3px!important;content:url('https://storage.ko-fi.com/cdn/cup-border.png')}.kofiimg:after{vertical-align:middle;height:25px;padding-top:0;padding-bottom:0;border:none;margin-top:0;margin-right:6px;margin-left:0;margin-bottom:4px!important;content:url('https://storage.ko-fi.com/cdn/whitelogo.svg')}.btn-container{display:inline-block!important;white-space:nowrap;min-width:160px}span.kofitext{color:#fff !important;letter-spacing: -0.15px!important;text-wrap:none;vertical-align:middle;line-height:30px !important;padding:0;text-align:center;text-decoration:none!important; text-shadow: 0 1px 1px rgba(34, 34, 34, 0.05);}.kofitext a{color:#fff !important;text-decoration:none:important;}.kofitext a:hover{color:#fff !important;text-decoration:none}a.kofi-button{box-shadow: 1px 1px 0px rgba(0, 0, 0, 0.2);line-height:27px!important;min-width:150px;display:inline-block!important;background-color:#29abe0;padding:2px 12px !important;text-align:center !important;border-radius:7px;color:#fff;cursor:pointer;overflow-wrap:break-word;vertical-align:middle;border:0 none #fff !important;font-family:'Quicksand',Helvetica,Century Gothic,sans-serif !important;text-decoration:none;text-shadow:none;font-weight:700!important;font-size:14px !important}a.kofi-button:visited{color:#fff !important;text-decoration:none !important}a.kofi-button:hover{opacity:.85;color:#f5f5f5 !important;text-decoration:none !important}a.kofi-button:active{color:#f5f5f5 !important;text-decoration:none !important}.kofitext img.kofiimg {height:15px!important;width:22px!important;display: initial;animation: kofi-wiggle 3s infinite;}";
|
| 17 |
+
style = style + "@keyframes kofi-wiggle{0%{transform:rotate(0) scale(1)}60%{transform:rotate(0) scale(1)}75%{transform:rotate(0) scale(1.12)}80%{transform:rotate(0) scale(1.1)}84%{transform:rotate(-10deg) scale(1.1)}88%{transform:rotate(10deg) scale(1.1)}92%{transform:rotate(-10deg) scale(1.1)}96%{transform:rotate(10deg) scale(1.1)}100%{transform:rotate(0) scale(1)}}";
|
| 18 |
+
style = "<style>" + style + "</style>";
|
| 19 |
+
html =
|
| 20 |
+
"<link href='https://fonts.googleapis.com/css?family=Quicksand:400,700' rel='stylesheet' type='text/css'>";
|
| 21 |
+
html +=
|
| 22 |
+
'<div class=btn-container><a title="Support me on ko-fi.com" class="kofi-button" style="background-color:[color]; text-decoration: none;" href="https://ko-fi.com/[id]" target="_blank"> <span class="kofitext"><img src="https://storage.ko-fi.com/cdn/cup-border.png" alt="Ko-fi donations" class="kofiimg"/>[text]</span></a></div>';
|
| 23 |
+
},
|
| 24 |
+
getHTML: function () {
|
| 25 |
+
var rtn = style + html.replace("[color]", color).replace("[text]", text).replace("[id]", id);
|
| 26 |
+
return rtn;
|
| 27 |
+
},
|
| 28 |
+
draw: function () {
|
| 29 |
+
document.writeln(style + html.replace("[color]", color).replace("[text]", text).replace("[id]", id));
|
| 30 |
+
}
|
| 31 |
+
};
|
| 32 |
+
}());
|
| 33 |
+
const checkElement = setInterval(() => {
|
| 34 |
+
const kofiDiv = document.getElementById('kofi');
|
| 35 |
+
if (kofiDiv) {
|
| 36 |
+
clearInterval(checkElement);
|
| 37 |
+
kofiwidget2.init('Buy me a coffee', '#f87316', 'Y8Y0STZND');
|
| 38 |
+
kofiDiv.innerHTML = kofiwidget2.getHTML();
|
| 39 |
+
}
|
| 40 |
+
}, 100);
|
| 41 |
+
}
|
| 42 |
+
"""
|