Update app.py
Browse files
app.py
CHANGED
|
@@ -4,7 +4,7 @@ import numpy as np
|
|
| 4 |
import gradio as gr
|
| 5 |
import requests
|
| 6 |
import pandas as pd
|
| 7 |
-
import datetime
|
| 8 |
from typing import List, Dict, Any
|
| 9 |
import hashlib
|
| 10 |
|
|
@@ -25,7 +25,15 @@ try:
|
|
| 25 |
VECTOR_DIM = 384
|
| 26 |
INDEX_FILE = "incident_vectors.index"
|
| 27 |
TEXTS_FILE = "incident_texts.json"
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
if os.path.exists(INDEX_FILE):
|
| 31 |
index = faiss.read_index(INDEX_FILE)
|
|
@@ -39,6 +47,7 @@ except ImportError as e:
|
|
| 39 |
print(f"Warning: FAISS or SentenceTransformers not available: {e}")
|
| 40 |
index = None
|
| 41 |
incident_texts = []
|
|
|
|
| 42 |
|
| 43 |
def save_index():
|
| 44 |
"""Save FAISS index and incident texts"""
|
|
|
|
| 4 |
import gradio as gr
|
| 5 |
import requests
|
| 6 |
import pandas as pd
|
| 7 |
+
import datetime # ← THIS WAS MISSING
|
| 8 |
from typing import List, Dict, Any
|
| 9 |
import hashlib
|
| 10 |
|
|
|
|
| 25 |
VECTOR_DIM = 384
|
| 26 |
INDEX_FILE = "incident_vectors.index"
|
| 27 |
TEXTS_FILE = "incident_texts.json"
|
| 28 |
+
|
| 29 |
+
# Try to load model with error handling
|
| 30 |
+
try:
|
| 31 |
+
model = SentenceTransformer("sentence-transformers/all-MiniLM-L6-v2")
|
| 32 |
+
except Exception as e:
|
| 33 |
+
print(f"Model loading warning: {e}")
|
| 34 |
+
# Fallback to direct loading
|
| 35 |
+
from sentence_transformers import SentenceTransformer as ST
|
| 36 |
+
model = ST("sentence-transformers/all-MiniLM-L6-v2")
|
| 37 |
|
| 38 |
if os.path.exists(INDEX_FILE):
|
| 39 |
index = faiss.read_index(INDEX_FILE)
|
|
|
|
| 47 |
print(f"Warning: FAISS or SentenceTransformers not available: {e}")
|
| 48 |
index = None
|
| 49 |
incident_texts = []
|
| 50 |
+
model = None
|
| 51 |
|
| 52 |
def save_index():
|
| 53 |
"""Save FAISS index and incident texts"""
|