-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
192 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
flagged/ | ||
scripts/__pycache__ | ||
docker/__pycache__ | ||
docker/flagged | ||
docker/flagged | ||
qdrant_storage/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,5 @@ diffusers==0.27.2 | |
pydantic==2.6.4 | ||
qdrant_client==1.9.0 | ||
pillow==10.2.0 | ||
accelerate | ||
datasets==2.15.0 | ||
accelerate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
from transformers import AutoImageProcessor, AutoModel | ||
from utils import ImageDB | ||
from PIL import Image | ||
from qdrant_client import QdrantClient | ||
import gradio as gr | ||
from argparse import ArgumentParser | ||
import torch | ||
|
||
argparse = ArgumentParser() | ||
argparse.add_argument( | ||
"-m", | ||
"--model", | ||
help="HuggingFace Model identifier, such as 'google/flan-t5-base'", | ||
required=True, | ||
) | ||
|
||
argparse.add_argument( | ||
"-id", | ||
"--image_dimension", | ||
help="Dimension of the image (e.g. 512, 758, 384...)", | ||
required=False, | ||
default=512, | ||
type=int | ||
) | ||
|
||
argparse.add_argument( | ||
"-d", | ||
"--directory", | ||
help="Directory where all your pdfs of interest are stored", | ||
required=False, | ||
default="No directory" | ||
) | ||
|
||
|
||
args = argparse.parse_args() | ||
|
||
|
||
mod = args.model | ||
dirs = args.directory | ||
imd = args.image_dimension | ||
|
||
device = torch.device("cuda" if torch.cuda.is_available() else "cpu") | ||
processor = AutoImageProcessor.from_pretrained(mod) | ||
model = AutoModel.from_pretrained(mod).to(device) | ||
|
||
client = QdrantClient(host="host.docker.internal", port=6333) | ||
imdb = ImageDB(dirs, processor, model, client, imd) | ||
print(imdb.collection_name) | ||
imdb.create_dataset() | ||
imdb.to_collection() | ||
|
||
|
||
def see_images(dataset, results): | ||
images = [] | ||
for i in range(len(results)): | ||
img = dataset[results[0].id]['image'] | ||
images.append(img) | ||
return images | ||
|
||
def process_img(image): | ||
global imdb | ||
results = imdb.searchDB(Image.fromarray(image)) | ||
images = see_images(imdb.dataset, results) | ||
return images | ||
|
||
|
||
iface = gr.Interface( | ||
title="everything-ai-retrievalimg", | ||
fn=process_img, | ||
inputs=gr.Image(label="Input Image"), | ||
outputs=gr.Gallery(label="Matching Images"), | ||
) | ||
|
||
iface.launch(server_name="0.0.0.0", share=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.