Skip to content

Instantly share code, notes, and snippets.

View idontcalculate's full-sized avatar
👾

Sirius1389 idontcalculate

👾
View GitHub Profile
from query import search_books
def main():
query_text = "carl sagan, cosmos"
results = search_books(query_text)
if not results:
print("No results found")
else:
for point in results:
import os
from qdrant_client import QdrantClient
from fastembed import TextEmbedding
from dotenv import load_dotenv
from qdrant_client.http.models import Distance, VectorParams
# Load environment variables from a .env file
load_dotenv()
# Access the environment variables
import os
import csv
from concurrent.futures import ThreadPoolExecutor
from qdrant_client import QdrantClient
from qdrant_client.http.models import PointStruct
from fastembed import TextEmbedding
from dotenv import load_dotenv
# Load environment variables from a .env file
load_dotenv()
from config import COLLECTION_NAME
import os
import csv
from qdrant_client.http.models import VectorParams, PointStruct
from dotenv import load_dotenv
from generate_embedding import get_book_vector
from connect_qdrant import get_qdrant_client
load_dotenv()
qdrant_client = get_qdrant_client()
from fastembed.embedding import TextEmbedding
def get_book_vector(book_data):
embedder = TextEmbedding(model_name="BAAI/bge-base-en")
text = f"{book_data['title']} {book_data['description']}"
vector = list(embedder.embed(text))
return vector[0] # Since embed returns a generator, we convert it to a list and take the first item.
def get_query_vector(query_text):
embedder = TextEmbedding(model_name="BAAI/bge-base-en")
from qdrant_client import QdrantClient
from qdrant_client.http.models import Distance, VectorParams
from config import QDRANT_API_KEY, QDRANT_URL
def get_qdrant_client():
qdrant_client = QdrantClient(
url=QDRANT_URL,
api_key=QDRANT_API_KEY,
)
# Ensure the collection exists
@idontcalculate
idontcalculate / vggtunedgr.py
Created May 17, 2024 20:07
gradio wrapper around predictions
import tensorflow as tf
from tensorflow.keras.models import load_model
import gradio as gr
import numpy as np
from PIL import Image
# Load the saved model
model = load_model("modelVGG16.h5")
# Define the prediction function
import tensorflow as tf
from tensorflow.keras.applications import VGG16
from tensorflow.keras import layers, models, optimizers
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.callbacks import EarlyStopping
# Load the pre-trained VGG16 model without the top layer
base_model = VGG16(input_shape=(256, 256, 3), include_top=False, weights='imagenet')
# Freeze the convolutional base
@idontcalculate
idontcalculate / vgg.py
Created May 17, 2024 19:15
example of transfer learning with tf hub models
from tensorflow.keras.applications import VGG16
from tensorflow.keras import layers, models
from tensorflow.keras.optimizers import Adam
from tensorflow.keras.losses import BinaryCrossentropy
from tensorflow.keras.metrics import BinaryAccuracy
# Load the pre-trained VGG16 model without the top layer
pretrained = VGG16(input_shape=(256, 256, 3), include_top=False, weights="imagenet")
pretrained.trainable = False
from llama_index.agent import FnRetrieverOpenAIAgent
from llama_index.llms import OpenAI
# Initialize the LLM
llm = OpenAI(model="gpt-3.5-turbo-0613")
# Initialize the FnRetrieverOpenAIAgent
top_agent = FnRetrieverOpenAIAgent.from_retriever(
obj_index.as_retriever(similarity_top_k=4),
system_prompt=""" \