Spaces:
Sleeping
Sleeping
Ankitajadhav
commited on
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# import packages
|
2 |
+
import gradio as gr
|
3 |
+
import copy
|
4 |
+
from llama_cpp import Llama
|
5 |
+
from huggingface_hub import hf_hub_download
|
6 |
+
import chromadb
|
7 |
+
from chromadb.utils.embedding_functions import OpenCLIPEmbeddingFunction
|
8 |
+
from chromadb.utils.data_loaders import ImageLoader
|
9 |
+
from chromadb.config import Settings
|
10 |
+
from datasets import load_dataset
|
11 |
+
import numpy as np
|
12 |
+
from tqdm import tqdm
|
13 |
+
import shutil
|
14 |
+
import os
|
15 |
+
from chromadb.utils import embedding_functions
|
16 |
+
import gradio as gr
|
17 |
+
from PIL import Image
|
18 |
+
import requests
|
19 |
+
from io import BytesIO
|
20 |
+
from transformers import pipeline
|
21 |
+
from bark import SAMPLE_RATE, generate_audio, preload_models
|
22 |
+
|
23 |
+
# Initialize the Llama model
|
24 |
+
llm = Llama(
|
25 |
+
## original model
|
26 |
+
# model_path=hf_hub_download(
|
27 |
+
# repo_id="microsoft/Phi-3-mini-4k-instruct-gguf",
|
28 |
+
# filename="Phi-3-mini-4k-instruct-q4.gguf",
|
29 |
+
# ),
|
30 |
+
## compressed model
|
31 |
+
model_path=hf_hub_download(
|
32 |
+
repo_id="TheBloke/CapybaraHermes-2.5-Mistral-7B-GGUF",
|
33 |
+
filename="capybarahermes-2.5-mistral-7b.Q2_K.gguf",
|
34 |
+
),
|
35 |
+
n_ctx=2048,
|
36 |
+
n_gpu_layers=50, # Adjust based on your VRAM
|
37 |
+
)
|
38 |
+
|
39 |
+
# use of clip model for embedding
|
40 |
+
client = chromadb.PersistentClient(path="DB")
|
41 |
+
|
42 |
+
embedding_function = OpenCLIPEmbeddingFunction()
|
43 |
+
image_loader = ImageLoader() # must be if you reads from URIs
|
44 |
+
|
45 |
+
# initialize separate collection for image and text data
|
46 |
+
collection_images = client.create_collection(
|
47 |
+
name='collection_images',
|
48 |
+
embedding_function=embedding_function,
|
49 |
+
data_loader=image_loader)
|
50 |
+
|
51 |
+
collection_text = client.create_collection(
|
52 |
+
name='collection_text',
|
53 |
+
embedding_function=embedding_function,
|
54 |
+
)
|
55 |
+
|
56 |
+
# Get the uris to the images
|
57 |
+
IMAGE_FOLDER = 'Moin_Von_Bremen/images'
|
58 |
+
|
59 |
+
|
60 |
+
image_uris = sorted([os.path.join(IMAGE_FOLDER, image_name) for image_name in os.listdir(IMAGE_FOLDER) if not image_name.endswith('.txt')])
|
61 |
+
ids = [str(i) for i in range(len(image_uris))]
|
62 |
+
|
63 |
+
collection_images.add(ids=ids, uris=image_uris)
|