Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,7 +8,6 @@ import pandas as pd
|
|
| 8 |
from sentence_transformers import SentenceTransformer
|
| 9 |
from flask import Flask, request, jsonify, render_template
|
| 10 |
from flask_cors import CORS
|
| 11 |
-
from pyngrok import ngrok
|
| 12 |
import requests
|
| 13 |
import cloudinary
|
| 14 |
import cloudinary.uploader
|
|
@@ -44,9 +43,9 @@ CLOUDINARY_API_KEY = os.getenv("CLOUDINARY_API_KEY", "default_key")
|
|
| 44 |
CLOUDINARY_API_SECRET = os.getenv("CLOUDINARY_API_SECRET", "default_secret")
|
| 45 |
|
| 46 |
# Define paths for models and data
|
| 47 |
-
MODEL_PATH = os.path.join("models", "model_state_dict.pth")
|
| 48 |
-
FAISS_INDEX_PATH = os.path.join("models", "property_faiss.index")
|
| 49 |
-
DATASET_PATH = os.path.join("
|
| 50 |
MODEL_DIR = os.path.join("models", "llm_model")
|
| 51 |
|
| 52 |
# Check device
|
|
@@ -61,8 +60,8 @@ def load_sentence_transformer():
|
|
| 61 |
print("Loading SentenceTransformer model...")
|
| 62 |
try:
|
| 63 |
model_embedding = SentenceTransformer("jinaai/jina-embeddings-v3", trust_remote_code=True).to(device)
|
| 64 |
-
|
| 65 |
-
|
| 66 |
state_dict = torch.load(MODEL_PATH, map_location=device)
|
| 67 |
|
| 68 |
# Dequantize if needed
|
|
@@ -82,6 +81,8 @@ def load_sentence_transformer():
|
|
| 82 |
# Load FAISS index
|
| 83 |
def load_faiss_index():
|
| 84 |
print("Loading FAISS index...")
|
|
|
|
|
|
|
| 85 |
index = faiss.read_index(FAISS_INDEX_PATH)
|
| 86 |
print("FAISS index loaded successfully.")
|
| 87 |
return index
|
|
@@ -89,6 +90,8 @@ def load_faiss_index():
|
|
| 89 |
# Load dataset
|
| 90 |
def load_dataset():
|
| 91 |
print("Loading dataset...")
|
|
|
|
|
|
|
| 92 |
df = pd.read_csv(DATASET_PATH)
|
| 93 |
print("Dataset loaded successfully.")
|
| 94 |
return df
|
|
|
|
| 8 |
from sentence_transformers import SentenceTransformer
|
| 9 |
from flask import Flask, request, jsonify, render_template
|
| 10 |
from flask_cors import CORS
|
|
|
|
| 11 |
import requests
|
| 12 |
import cloudinary
|
| 13 |
import cloudinary.uploader
|
|
|
|
| 43 |
CLOUDINARY_API_SECRET = os.getenv("CLOUDINARY_API_SECRET", "default_secret")
|
| 44 |
|
| 45 |
# Define paths for models and data
|
| 46 |
+
MODEL_PATH = os.path.join("models", "new_rag_model", "model_state_dict.pth")
|
| 47 |
+
FAISS_INDEX_PATH = os.path.join("models", "new_rag_model", "property_faiss.index")
|
| 48 |
+
DATASET_PATH = os.path.join("models", "new_rag_model", "property_data.csv")
|
| 49 |
MODEL_DIR = os.path.join("models", "llm_model")
|
| 50 |
|
| 51 |
# Check device
|
|
|
|
| 60 |
print("Loading SentenceTransformer model...")
|
| 61 |
try:
|
| 62 |
model_embedding = SentenceTransformer("jinaai/jina-embeddings-v3", trust_remote_code=True).to(device)
|
| 63 |
+
if not os.path.exists(MODEL_PATH):
|
| 64 |
+
raise FileNotFoundError(f"Model state dict not found at {MODEL_PATH}. Please ensure the file exists.")
|
| 65 |
state_dict = torch.load(MODEL_PATH, map_location=device)
|
| 66 |
|
| 67 |
# Dequantize if needed
|
|
|
|
| 81 |
# Load FAISS index
|
| 82 |
def load_faiss_index():
|
| 83 |
print("Loading FAISS index...")
|
| 84 |
+
if not os.path.exists(FAISS_INDEX_PATH):
|
| 85 |
+
raise FileNotFoundError(f"FAISS index not found at {FAISS_INDEX_PATH}. Please ensure the file exists.")
|
| 86 |
index = faiss.read_index(FAISS_INDEX_PATH)
|
| 87 |
print("FAISS index loaded successfully.")
|
| 88 |
return index
|
|
|
|
| 90 |
# Load dataset
|
| 91 |
def load_dataset():
|
| 92 |
print("Loading dataset...")
|
| 93 |
+
if not os.path.exists(DATASET_PATH):
|
| 94 |
+
raise FileNotFoundError(f"Dataset file not found at {DATASET_PATH}. Please ensure the file exists.")
|
| 95 |
df = pd.read_csv(DATASET_PATH)
|
| 96 |
print("Dataset loaded successfully.")
|
| 97 |
return df
|