File size: 1,515 Bytes
f457390
7f0b913
 
 
 
 
 
f457390
7f0b913
 
 
 
f457390
 
7f53b0a
f457390
 
 
 
fa2cb47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8a2c9bc
 
 
 
 
 
 
 
 
fa2cb47
 
 
 
 
 
 
 
8a2c9bc
 
 
 
 
 
 
 
 
 
 
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
53
54
55
56
57
58
59
60
61
62
63
64
import gradio as gr
import os
import skimage
import matplotlib.pyplot as plt
from PIL import Image
import numpy as np
from collections import OrderedDict
import torch
from imagebind import data
from imagebind.models import imagebind_model
from imagebind.models.imagebind_model import ModalityType
import torch.nn as nn


device = "cpu" #"cuda:0" if torch.cuda.is_available() else "cpu"
model = imagebind_model.imagebind_huge(pretrained=True)
model.eval()
model.to(device)

def image_text_zeroshot(text):
    # labels = [text]
    # inputs = {
    #     ModalityType.TEXT: data.load_and_transform_text(labels, device)
    # }

    # with torch.no_grad():
    #     embeddings = model(inputs)

    # # scores = (
    # #     torch.softmax(
    # #         embeddings[ModalityType.VISION] @ embeddings[ModalityType.TEXT].T, dim=-1
    # #     )
    # #     .squeeze(0)
    # #     .tolist()
    # # )

    score_dict = "./assets/ICA-Logo.png" #{label: score for label, score in zip(labels, scores)}

    return score_dict


def main():

    iface = gr.Interface(
        fn=image_text_zeroshot,
        inputs="text",
        outputs="file",
        live=True,
        capture_session=True,
        title="Texto para Imagem",
        description="Digite um texto e obtenha uma imagem com o texto.",
        allow_flagging=False,
    )

    iface.launch()



# def image_classifier(inp):
#     return {'cat': 0.3, 'dog': 0.7}

# demo = gr.Interface(fn=image_classifier, inputs="image", outputs="label")
# demo.launch()