Wills17 commited on
Commit
76c79b2
·
verified ·
1 Parent(s): 90bd68b

Update flask_app.py

Browse files
Files changed (1) hide show
  1. flask_app.py +7 -2
flask_app.py CHANGED
@@ -6,6 +6,11 @@ import re
6
  import tempfile
7
  from flask import Flask, request, jsonify, render_template
8
 
 
 
 
 
 
9
 
10
  # Disable CUDA and excessive parallel threads to save memory
11
  os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
@@ -86,8 +91,8 @@ def upload_file():
86
 
87
  # Light embedding model (fast + low memory)
88
  try:
89
- embeds = HuggingFaceEmbeddings(model_name="sentence-transformers/paraphrase-MiniLM-L3-v2")
90
- # embeds = HuggingFaceEmbeddings(model_name="./models/paraphrase-MiniLM-L3-v2")
91
  vector_store = FAISS.from_documents(chunks, embeds)
92
  retriever = vector_store.as_retriever(search_type="similarity", search_kwargs={"k": 5})
93
 
 
6
  import tempfile
7
  from flask import Flask, request, jsonify, render_template
8
 
9
+ # Pre-download and save the embedding model
10
+ from sentence_transformers import SentenceTransformer
11
+ model = SentenceTransformer("sentence-transformers/paraphrase-MiniLM-L3-v2")
12
+ model.save("models/paraphrase-MiniLM-L3-v2")
13
+
14
 
15
  # Disable CUDA and excessive parallel threads to save memory
16
  os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
 
91
 
92
  # Light embedding model (fast + low memory)
93
  try:
94
+ # embeds = HuggingFaceEmbeddings(model_name="sentence-transformers/paraphrase-MiniLM-L3-v2")
95
+ embeds = HuggingFaceEmbeddings(model_name="./models/paraphrase-MiniLM-L3-v2") # local model (offline)
96
  vector_store = FAISS.from_documents(chunks, embeds)
97
  retriever = vector_store.as_retriever(search_type="similarity", search_kwargs={"k": 5})
98