Skip to content

A curated collection of practical AI projects implementing OCR systems, RAG, AI agents, and other AI use cases.

fix(vision_rag): remove unresolved merge conflict markers

Rudy Celekli608b6a8b1a83
diff --git a/rag_apps/vision_rag/.env.example b/rag_apps/vision_rag/.env.example
index 1360c8a..9752a2a 100644
--- a/rag_apps/vision_rag/.env.example
+++ b/rag_apps/vision_rag/.env.example
@@ -1,11 +1,7 @@
-<<<<<<< HEAD
-OPENAI_API_KEY=your_openai_api_key_here
-=======
# Mistral API key used for Mistral Small (vision) question answering.
# Get one free at https://platform.mistral.ai
MISTRAL_API_KEY=your_mistral_api_key_here
# Cohere API key used for embed-v4.0 multimodal embeddings.
# Get one free at https://cohere.com
->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a
COHERE_API_KEY=your_cohere_api_key_here
diff --git a/rag_apps/vision_rag/app.py b/rag_apps/vision_rag/app.py
index 329097e..3179340 100644
--- a/rag_apps/vision_rag/app.py
+++ b/rag_apps/vision_rag/app.py
@@ -1,21 +1,14 @@
-<<<<<<< HEAD
-=======
"""
VisionRAG: Multimodal Search & Visual Question Answering Streamlit app.
"""
->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a
import streamlit as st
import os
import datetime
from PIL import Image
import numpy as np
from dotenv import load_dotenv, find_dotenv
-<<<<<<< HEAD
-from utils import get_cohere_embedding, openai_vqa, pdf_to_images, image_to_bytes, find_most_similar
-=======
from utils import get_cohere_embedding, mistral_vqa, pdf_to_images, image_to_bytes, find_most_similar
->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a
# Load environment variables
load_dotenv(find_dotenv())
@@ -25,11 +18,7 @@ st.set_page_config(page_title="VisionRAG: Multimodal Search & VQA", layout="wide
st.title("VisionRAG: Multimodal Search & Visual Question Answering")
cohere_api = os.getenv("COHERE_API_KEY")
-<<<<<<< HEAD
-openai_api = os.getenv("OPENAI_API_KEY")
-=======
mistral_api = os.getenv("MISTRAL_API_KEY")
->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a
# Initialize session state
if 'items' not in st.session_state:
@@ -117,13 +106,8 @@ with st.form("question_form"):
# Process question submission
if submit_button:
-<<<<<<< HEAD
- if not cohere_api or not openai_api:
- st.error("Please provide both Cohere and OpenAI API keys.")
-=======
if not cohere_api or not mistral_api:
st.error("Please provide both Cohere and Mistral API keys.")
->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a
elif not question:
st.error("Please enter a question.")
elif not st.session_state['items']:
@@ -144,17 +128,10 @@ if submit_button:
idx, sim = find_most_similar(q_emb, emb_list)
best_item = st.session_state['items'][idx]
-<<<<<<< HEAD
- # Generate answer using OpenAI
- st.info("Generating answer with OpenAI Vision...")
- img_bytes = image_to_bytes(best_item['img'])
- answer = openai_vqa(openai_api, img_bytes, question)
-=======
# Generate answer using Mistral
st.info("Generating answer with Mistral Vision...")
img_bytes = image_to_bytes(best_item['img'])
answer = mistral_vqa(mistral_api, img_bytes, question)
->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a
# Add to conversation history
timestamp = datetime.datetime.now().strftime("%H:%M:%S")
diff --git a/rag_apps/vision_rag/requirements.txt b/rag_apps/vision_rag/requirements.txt
index 98efa30..c0d5a5d 100644
--- a/rag_apps/vision_rag/requirements.txt
+++ b/rag_apps/vision_rag/requirements.txt
@@ -1,10 +1,6 @@
streamlit
cohere
-<<<<<<< HEAD
-openai==1.83.0
-=======
mistralai
->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a
python-dotenv
PyMuPDF
Pillow
diff --git a/rag_apps/vision_rag/utils.py b/rag_apps/vision_rag/utils.py
index cdd7dc1..a7bf04f 100644
--- a/rag_apps/vision_rag/utils.py
+++ b/rag_apps/vision_rag/utils.py
@@ -40,28 +40,6 @@ def get_cohere_embedding(api_key, input_data, input_type='text'):
else:
raise ValueError("input_type must be 'text' or 'image'")
-<<<<<<< HEAD
-# --- OpenAI GPT-4o-mini VQA ---
-def openai_vqa(api_key, image_bytes, question):
- """
- Send image and question to GPT-4o-mini for Visual Question Answering.
-
- Args:
- api_key (str): OpenAI API key
- image_bytes (bytes): Image data
- question (str): Question about the image
-
- Returns:
- str: Generated answer
- """
- from openai import OpenAI
- client = OpenAI(api_key=api_key, timeout=30.0)
-
- image_b64 = base64.b64encode(image_bytes).decode('utf-8')
-
- response = client.chat.completions.create(
- model="gpt-4o-mini",
-=======
# --- Mistral Small VQA ---
def mistral_vqa(api_key, image_bytes, question):
"""
@@ -82,7 +60,6 @@ def mistral_vqa(api_key, image_bytes, question):
response = client.chat.complete(
model="mistral-small-latest",
->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a
messages=[
{
"role": "user",
@@ -90,11 +67,7 @@ def mistral_vqa(api_key, image_bytes, question):
{"type": "text", "text": question},
{
"type": "image_url",
-<<<<<<< HEAD
- "image_url": {"url": f"data:image/png;base64,{image_b64}"},
-=======
"image_url": f"data:image/png;base64,{image_b64}",
->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a
},
],
}