Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -153,8 +153,27 @@ class QuantumDocumentManager:
|
|
153 |
"""
|
154 |
return f"{hashlib.sha256(content.encode()).hexdigest()[:16]}-{int(time.time())}"
|
155 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
156 |
# Initialize document collections
|
157 |
-
qdm =
|
158 |
research_docs = qdm.create_collection([
|
159 |
"Research Report: Results of a New AI Model Improving Image Recognition Accuracy to 98%",
|
160 |
"Academic Paper Summary: Why Transformers Became the Mainstream Architecture in Natural Language Processing",
|
@@ -192,7 +211,6 @@ class ResearchRetriever:
|
|
192 |
def retrieve(self, query: str, domain: str) -> List[Any]:
|
193 |
"""
|
194 |
Retrieves documents based on the query and domain.
|
195 |
-
For now, domain differentiation is minimal; however, you can extend this method to use domain-specific collections.
|
196 |
"""
|
197 |
try:
|
198 |
return self.research_retriever.invoke(query)
|
@@ -386,7 +404,6 @@ class MultiModalRetriever:
|
|
386 |
self.text_retriever = text_retriever
|
387 |
self.clip_model = clip_model
|
388 |
self.clip_processor = clip_processor
|
389 |
-
# Provide required positional arguments: name and description
|
390 |
self.code_retriever = create_retriever_tool([], "Code Retriever", "Retriever for code snippets")
|
391 |
|
392 |
def retrieve(self, query: str, domain: str) -> Dict[str, List]:
|
@@ -779,7 +796,7 @@ multi_retriever = MultiModalRetriever(retriever.research_retriever, clip_model,
|
|
779 |
# ------------------------------
|
780 |
# Updated Document Processing for Multi-Modal Documents
|
781 |
# ------------------------------
|
782 |
-
class
|
783 |
"""Extended with multi-modal document handling."""
|
784 |
def create_image_collection(self, image_paths: List[str]):
|
785 |
embeddings = []
|
@@ -795,7 +812,8 @@ class QuantumDocumentManager(QuantumDocumentManager):
|
|
795 |
collection_name="neuro_images"
|
796 |
)
|
797 |
|
798 |
-
# Initialize image collection
|
|
|
799 |
qdm.create_image_collection([
|
800 |
"data/images/quantum_computing.png",
|
801 |
"data/images/neural_arch.png"
|
|
|
153 |
"""
|
154 |
return f"{hashlib.sha256(content.encode()).hexdigest()[:16]}-{int(time.time())}"
|
155 |
|
156 |
+
# ------------------------------
|
157 |
+
# Extended Quantum Document Manager for Multi-Modal Documents
|
158 |
+
# ------------------------------
|
159 |
+
class ExtendedQuantumDocumentManager(QuantumDocumentManager):
|
160 |
+
"""Extended with multi-modal document handling."""
|
161 |
+
def create_image_collection(self, image_paths: List[str]):
|
162 |
+
embeddings = []
|
163 |
+
for img_path in image_paths:
|
164 |
+
image = Image.open(img_path)
|
165 |
+
inputs = clip_processor(images=image, return_tensors="pt")
|
166 |
+
with torch.no_grad():
|
167 |
+
emb = clip_model.get_image_features(**inputs)
|
168 |
+
embeddings.append(emb.numpy())
|
169 |
+
return Chroma.from_embeddings(
|
170 |
+
embeddings=embeddings,
|
171 |
+
documents=image_paths,
|
172 |
+
collection_name="neuro_images"
|
173 |
+
)
|
174 |
+
|
175 |
# Initialize document collections
|
176 |
+
qdm = ExtendedQuantumDocumentManager()
|
177 |
research_docs = qdm.create_collection([
|
178 |
"Research Report: Results of a New AI Model Improving Image Recognition Accuracy to 98%",
|
179 |
"Academic Paper Summary: Why Transformers Became the Mainstream Architecture in Natural Language Processing",
|
|
|
211 |
def retrieve(self, query: str, domain: str) -> List[Any]:
|
212 |
"""
|
213 |
Retrieves documents based on the query and domain.
|
|
|
214 |
"""
|
215 |
try:
|
216 |
return self.research_retriever.invoke(query)
|
|
|
404 |
self.text_retriever = text_retriever
|
405 |
self.clip_model = clip_model
|
406 |
self.clip_processor = clip_processor
|
|
|
407 |
self.code_retriever = create_retriever_tool([], "Code Retriever", "Retriever for code snippets")
|
408 |
|
409 |
def retrieve(self, query: str, domain: str) -> Dict[str, List]:
|
|
|
796 |
# ------------------------------
|
797 |
# Updated Document Processing for Multi-Modal Documents
|
798 |
# ------------------------------
|
799 |
+
class ExtendedQuantumDocumentManager(ExtendedQuantumDocumentManager):
|
800 |
"""Extended with multi-modal document handling."""
|
801 |
def create_image_collection(self, image_paths: List[str]):
|
802 |
embeddings = []
|
|
|
812 |
collection_name="neuro_images"
|
813 |
)
|
814 |
|
815 |
+
# Initialize image collection using the extended manager
|
816 |
+
qdm = ExtendedQuantumDocumentManager()
|
817 |
qdm.create_image_collection([
|
818 |
"data/images/quantum_computing.png",
|
819 |
"data/images/neural_arch.png"
|