Spaces:
Runtime error
Runtime error
test
Browse files- app.py +41 -44
- assets/ICA-Logo.png +0 -0
app.py
CHANGED
|
@@ -17,47 +17,44 @@ model = imagebind_model.imagebind_huge(pretrained=True)
|
|
| 17 |
model.eval()
|
| 18 |
model.to(device)
|
| 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 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
#
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
demo = gr.Interface(fn=image_classifier, inputs="image", outputs="label")
|
| 63 |
-
demo.launch()
|
|
|
|
| 17 |
model.eval()
|
| 18 |
model.to(device)
|
| 19 |
|
| 20 |
+
def image_text_zeroshot(texts):
|
| 21 |
+
labels = [texts]
|
| 22 |
+
inputs = {
|
| 23 |
+
ModalityType.TEXT: data.load_and_transform_text(labels, device)
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
with torch.no_grad():
|
| 27 |
+
embeddings = model(inputs)
|
| 28 |
+
|
| 29 |
+
# scores = (
|
| 30 |
+
# torch.softmax(
|
| 31 |
+
# embeddings[ModalityType.VISION] @ embeddings[ModalityType.TEXT].T, dim=-1
|
| 32 |
+
# )
|
| 33 |
+
# .squeeze(0)
|
| 34 |
+
# .tolist()
|
| 35 |
+
# )
|
| 36 |
+
|
| 37 |
+
score_dict = "./assets/ICA-Logo.png" #{label: score for label, score in zip(labels, scores)}
|
| 38 |
+
|
| 39 |
+
return score_dict
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def main():
|
| 43 |
+
|
| 44 |
+
iface = gr.Interface(
|
| 45 |
+
fn= image_text_zeroshot(texts),
|
| 46 |
+
inputs = gr.inputs.Textbox(lines=1, label="texts"),
|
| 47 |
+
outputs = gr.inputs.Image(type="filepath", label="Output image"),
|
| 48 |
+
description="""...""",
|
| 49 |
+
title="ImageBind",
|
| 50 |
+
)
|
| 51 |
+
|
| 52 |
+
iface.launch()
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
# def image_classifier(inp):
|
| 57 |
+
# return {'cat': 0.3, 'dog': 0.7}
|
| 58 |
+
|
| 59 |
+
# demo = gr.Interface(fn=image_classifier, inputs="image", outputs="label")
|
| 60 |
+
# demo.launch()
|
|
|
|
|
|
|
|
|
assets/ICA-Logo.png
ADDED
|