File size: 1,432 Bytes
fcf06b7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
142e7ee
fcf06b7
 
c25fdc0
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
import assignment23
from assignment23 import make_train_valid_dfs 
from assignment23 import get_image_embeddings 
from assignment23 import inference_CLIP

import gradio as gr
import zipfile
import os
import pandas as pd
import subprocess


image_path = "./Images"
captions_path = "."
data_source = 'flickr8k.zip'

with zipfile.ZipFile(data_source, 'r') as zip_ref:
    zip_ref.extractall('.')


cmd = "pwd"
output1 = subprocess.check_output(cmd, shell=True).decode("utf-8")



cmd = "ls -l"
output1 = subprocess.check_output(cmd, shell=True).decode("utf-8")




df = pd.read_csv("captions.txt")
df['id'] = [id_ for id_ in range(df.shape[0] // 5) for _ in range(5)]
df.to_csv("captions.csv", index=False)
df = pd.read_csv("captions.csv")


_, valid_df = make_train_valid_dfs()

model, image_embeddings = get_image_embeddings(valid_df, "best.pt")


examples = ["man and women on road"]

def greet(query_text):
    print("Going to invoke inference_CLIP")
    return inference_CLIP(query_text)
    
gallery = gr.Gallery(
           label="CLIP result images", show_label=True, elem_id="gallery", 
           columns=[3], rows=[3], object_fit="contain", height="auto")

demo = gr.Interface(fn=greet, 
                    inputs=gr.Dropdown(choices=examples, label="Search Image by text prompt"), 
                    outputs=gallery,
                    title="OpenAI CLIP-Contrastive Language-Image Pre-training")


demo.launch("debug")