Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
CHANGED
@@ -13,7 +13,7 @@ QWEN_API_URL = "Qwen/Qwen2.5-Max-Demo" # Gradio API for Qwen2.5 chat
|
|
13 |
CHUNK_SIZE = 800
|
14 |
TOP_K_RESULTS = 150
|
15 |
SIMILARITY_THRESHOLD = 0.4
|
16 |
-
PASSWORD_HASH = os.getenv("PASSWORD_HASH", "
|
17 |
|
18 |
BASE_SYSTEM_PROMPT = """
|
19 |
Répondez en français selon ces règles :
|
@@ -117,12 +117,18 @@ def create_new_database(file_content: str, db_name: str, password: str, progress
|
|
117 |
text_embeddings=list(zip(chunks, embeddings_list)),
|
118 |
embedding=embeddings
|
119 |
)
|
120 |
-
|
121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
|
123 |
# Verify files were created
|
124 |
if not os.path.exists(faiss_file) or not os.path.exists(pkl_file):
|
125 |
-
return
|
126 |
logging.info(f"FAISS database files created: {faiss_file}, {pkl_file}")
|
127 |
|
128 |
# Update the list of available databases
|
@@ -145,7 +151,11 @@ def generate_response(user_input: str, db_name: str) -> str:
|
|
145 |
if not os.path.exists(faiss_file) or not os.path.exists(pkl_file):
|
146 |
return f"Database '{db_name}' does not exist."
|
147 |
|
148 |
-
|
|
|
|
|
|
|
|
|
149 |
|
150 |
# Contextual search
|
151 |
docs_scores = vector_store.similarity_search_with_score(
|
|
|
13 |
CHUNK_SIZE = 800
|
14 |
TOP_K_RESULTS = 150
|
15 |
SIMILARITY_THRESHOLD = 0.4
|
16 |
+
PASSWORD_HASH = os.getenv("PASSWORD_HASH", "abc12345") # Use environment variable for password
|
17 |
|
18 |
BASE_SYSTEM_PROMPT = """
|
19 |
Répondez en français selon ces règles :
|
|
|
117 |
text_embeddings=list(zip(chunks, embeddings_list)),
|
118 |
embedding=embeddings
|
119 |
)
|
120 |
+
|
121 |
+
# Save FAISS database
|
122 |
+
try:
|
123 |
+
vector_store.save_local(".")
|
124 |
+
logging.info(f"FAISS database saved to: {faiss_file} and {pkl_file}")
|
125 |
+
except Exception as e:
|
126 |
+
logging.error(f"FAISS save error: {str(e)}")
|
127 |
+
return "Failed to save FAISS database. Please check logs for details.", []
|
128 |
|
129 |
# Verify files were created
|
130 |
if not os.path.exists(faiss_file) or not os.path.exists(pkl_file):
|
131 |
+
return "Failed to save FAISS database files. Please check file permissions.", []
|
132 |
logging.info(f"FAISS database files created: {faiss_file}, {pkl_file}")
|
133 |
|
134 |
# Update the list of available databases
|
|
|
151 |
if not os.path.exists(faiss_file) or not os.path.exists(pkl_file):
|
152 |
return f"Database '{db_name}' does not exist."
|
153 |
|
154 |
+
try:
|
155 |
+
vector_store = FAISS.load_local(".", embeddings, allow_dangerous_deserialization=True)
|
156 |
+
except Exception as e:
|
157 |
+
logging.error(f"FAISS load error: {str(e)}")
|
158 |
+
return "Failed to load FAISS database. Please check logs for details."
|
159 |
|
160 |
# Contextual search
|
161 |
docs_scores = vector_store.similarity_search_with_score(
|