Contextual_ChatBot / imagequerying.py
Pranjal Gupta
Contextual ChatBot
c7d967d
raw
history blame
1.76 kB
# import cv2
# import torch
# import ollama
# import base64
# import os
# import time
# from sentence_transformers import SentenceTransformer, util
# import chromadb
# import os
# from langchain.schema import Document # Import the Document class from LangChain
# import re
# import fitz
# from langchain_chroma import Chroma
# from chromadb.config import Settings, DEFAULT_DATABASE, DEFAULT_TENANT
# from chromadb.utils import embedding_functions
# from langchain.text_splitter import RecursiveCharacterTextSplitter
# from langchain.chains.qa_with_sources.retrieval import RetrievalQAWithSourcesChain
# from langchain_huggingface import HuggingFaceEmbeddings
# from langchain_core.prompts import PromptTemplate
# from langchain_core.output_parsers import StrOutputParser
# from langchain_ollama import ChatOllama
# def vision_model(file_path, query):
# """Processes an image and queries the LLaMA vision model."""
# print("<<<<< VISION MODEL STARTED >>>>>")
# image = cv2.imread(file_path)
# if image is None:
# return "Error: Failed to load image."
# _, buffer = cv2.imencode(".jpg", image)
# image_base64 = base64.b64encode(buffer).decode("utf-8")
# prompt = f"""
# Please describe the following image based on the given query.
# If the query is not relevant, respond with:
# "Sorry, I don't have enough information from this specific image."
# Query: {query}
# """
# try:
# response = ollama.chat(
# model="llama3.2-vision",
# messages=[{"role": "user", "content": prompt, "images": [image_base64]}],
# )
# return response.get("message", {}).get("content", "").strip()
# except Exception as e:
# return f"Error: {str(e)}"