unzip with verbose
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import s23_openai_clip
|
| 2 |
from s23_openai_clip import make_train_valid_dfs
|
| 3 |
from s23_openai_clip import get_image_embeddings
|
|
|
|
| 4 |
|
| 5 |
import gradio as gr
|
| 6 |
import zipfile
|
|
@@ -9,10 +10,27 @@ import zipfile
|
|
| 9 |
# query_text = "dogs on the grass"
|
| 10 |
image_path = "./Images"
|
| 11 |
captions_path = "."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
|
| 14 |
-
with zipfile.ZipFile('flickr8k.zip', 'r') as zip_ref:
|
| 15 |
-
zip_ref.extractall('Images')
|
| 16 |
|
| 17 |
_, valid_df = make_train_valid_dfs()
|
| 18 |
model, image_embeddings = get_image_embeddings(valid_df, "best.pt")
|
|
@@ -20,7 +38,7 @@ model, image_embeddings = get_image_embeddings(valid_df, "best.pt")
|
|
| 20 |
|
| 21 |
|
| 22 |
def greet(query_text):
|
| 23 |
-
return
|
| 24 |
|
| 25 |
|
| 26 |
gallery = gr.Gallery(
|
|
|
|
| 1 |
import s23_openai_clip
|
| 2 |
from s23_openai_clip import make_train_valid_dfs
|
| 3 |
from s23_openai_clip import get_image_embeddings
|
| 4 |
+
from s23_openai_clip import inference_CLIP
|
| 5 |
|
| 6 |
import gradio as gr
|
| 7 |
import zipfile
|
|
|
|
| 10 |
# query_text = "dogs on the grass"
|
| 11 |
image_path = "./Images"
|
| 12 |
captions_path = "."
|
| 13 |
+
data_source = 'flickr8k.zip'
|
| 14 |
+
entry_name = "Images"
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
z = zipfile.ZipFile(data_source)
|
| 18 |
+
entry_info = z.getinfo(entry_name)
|
| 19 |
+
i = z.open(entry_name)
|
| 20 |
+
o = open(image_path, 'w')
|
| 21 |
+
offset = 0
|
| 22 |
+
while True:
|
| 23 |
+
b = i.read(block_size)
|
| 24 |
+
offset += len(b)
|
| 25 |
+
set_percentage(float(offset)/float(entry_info.file_size) * 100.)
|
| 26 |
+
if b == '':
|
| 27 |
+
break
|
| 28 |
+
o.write(b)
|
| 29 |
+
i.close()
|
| 30 |
+
o.close()
|
| 31 |
+
set_attributes_from(entry_info)
|
| 32 |
|
| 33 |
+
|
|
|
|
|
|
|
| 34 |
|
| 35 |
_, valid_df = make_train_valid_dfs()
|
| 36 |
model, image_embeddings = get_image_embeddings(valid_df, "best.pt")
|
|
|
|
| 38 |
|
| 39 |
|
| 40 |
def greet(query_text):
|
| 41 |
+
return inference_CLIP(query_text)
|
| 42 |
|
| 43 |
|
| 44 |
gallery = gr.Gallery(
|