acecalisto3 commited on
Commit
b76e9b0
·
verified ·
1 Parent(s): 6e9a206

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -28
app.py CHANGED
@@ -303,44 +303,34 @@ class MultimodalRAG:
303
  except Exception as e:
304
  logger.error(f"Error loading template embeddings: {e}")
305
 
306
- def save_template_embeddings(self):
307
- """Save template embeddings to disk"""
308
  try:
309
- template_path = TEMPLATE_DIR / "template_embeddings.npz"
310
- np.savez(
311
- template_path,
312
- **self.template_embeddings
313
- )
 
 
 
 
 
 
 
314
  except Exception as e:
315
- logger.error(f"Error saving template embeddings: {e}")
 
316
 
317
- def encode_image(self, image: Image.Image) -> np.ndarray:
318
- """Encode image using BLIP"""
319
- try:
320
- model, processor = self.model_manager.load_model("image_processor")
321
-
322
- # Process image
323
- inputs = processor(images=image, return_tensors="pt").to(model.device)
324
-
325
- # Get image features using the proper method
326
- with torch.no_grad():
327
- outputs = model.get_image_features(**inputs)
328
- image_features = outputs.last_hidden_state.mean(dim=1) # Average pooling
329
-
330
- return image_features.cpu().numpy()
331
-
332
- except Exception as e:
333
- logger.error(f"Error encoding image: {str(e)}")
334
- raise ModelError(f"Error encoding image: {str(e)}")
335
-
336
  def encode_text(self, text: str) -> np.ndarray:
337
  """Encode text using sentence-transformers"""
338
-
339
  try:
340
  return self.text_encoder.encode(text)
341
  except Exception as e:
342
  raise ModelError(f"Error encoding text: {str(e)}")
343
 
 
 
344
  def generate_code(self, description: str, template_code: str) -> str:
345
  """Generate code using StarCoder"""
346
  try:
 
303
  except Exception as e:
304
  logger.error(f"Error loading template embeddings: {e}")
305
 
306
+ def encode_image(self, image: Image.Image) -> np.ndarray:
307
+ """Encode image using BLIP"""
308
  try:
309
+ model, processor = self.model_manager.load_model("image_processor")
310
+
311
+ # Process image
312
+ inputs = processor(images=image, return_tensors="pt").to(model.device)
313
+
314
+ # Get image features using the proper method
315
+ with torch.no_grad():
316
+ outputs = model.get_image_features(**inputs)
317
+ image_features = outputs.last_hidden_state.mean(dim=1) # Average pooling
318
+
319
+ return image_features.cpu().numpy()
320
+
321
  except Exception as e:
322
+ logger.error(f"Error encoding image: {str(e)}")
323
+ raise ModelError(f"Error encoding image: {str(e)}")
324
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
325
  def encode_text(self, text: str) -> np.ndarray:
326
  """Encode text using sentence-transformers"""
 
327
  try:
328
  return self.text_encoder.encode(text)
329
  except Exception as e:
330
  raise ModelError(f"Error encoding text: {str(e)}")
331
 
332
+ # ... rest of the MultimodalRAG class methods ...
333
+
334
  def generate_code(self, description: str, template_code: str) -> str:
335
  """Generate code using StarCoder"""
336
  try: