-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
41 lines (31 loc) · 1.35 KB
/
config.py
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
import os
from pinecone import Pinecone, ServerlessSpec
from transformers import CLIPProcessor, CLIPModel
from schemas.models import ProjectionLayer
def initialize_pinecone():
api_key = os.getenv("PINECONE_API_KEY")
if not api_key:
raise ValueError("Pinecone API key not found in environment variables")
pc = Pinecone(api_key=api_key)
index_name = os.getenv("PINECONE_INDEX_NAME", "default_index")
dimension = 256
if index_name not in pc.list_indexes().names():
pc.create_index(
name=index_name,
dimension=dimension,
metric="cosine",
spec=ServerlessSpec(cloud="aws", region="us-east-1"),
)
print(f"Index '{index_name}' created successfully.")
else:
print(f"Index '{index_name}' already exists. Using the existing index.")
return pc.Index(index_name)
def load_models():
model = CLIPModel.from_pretrained("openai/clip-vit-base-patch32")
processor = CLIPProcessor.from_pretrained("openai/clip-vit-base-patch32")
vision_input_dim = model.vision_model.config.hidden_size
text_input_dim = model.text_model.config.hidden_size
output_dim = 256
vision_projection = ProjectionLayer(vision_input_dim, output_dim)
text_projection = ProjectionLayer(text_input_dim, output_dim)
return model, processor, vision_projection, text_projection