Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -62,16 +62,16 @@ class SentenceTransformerEmbeddings:
|
|
62 |
print(f"Error loading SentenceTransformer: {e}")
|
63 |
raise
|
64 |
|
65 |
-
def __call__(self,
|
66 |
-
if isinstance(
|
67 |
-
|
68 |
try:
|
69 |
-
embeddings = self.model.encode(
|
70 |
return embeddings
|
71 |
except Exception as e:
|
72 |
print(f"Error generating embeddings: {e}")
|
73 |
# Fallback to simple embeddings if needed
|
74 |
-
return [[0.0] * 384 for _ in
|
75 |
|
76 |
# Initialize ChromaDB with a persistent directory in a writable location
|
77 |
persistent_dir = os.path.join("/tmp", "chroma_db")
|
@@ -285,7 +285,6 @@ def ask_question():
|
|
285 |
print(f"Error in /ask_question endpoint: {e}")
|
286 |
return jsonify({"response": "Sorry, an error occurred while generating the response."}), 500
|
287 |
|
288 |
-
|
289 |
if __name__ == '__main__':
|
290 |
# Make sure GOOGLE_API_KEY is checked before starting the app
|
291 |
if not GOOGLE_API_KEY:
|
@@ -293,4 +292,5 @@ if __name__ == '__main__':
|
|
293 |
else:
|
294 |
# Use port 7860 for Hugging Face Spaces compatibility
|
295 |
port = int(os.environ.get("PORT", 7860))
|
296 |
-
app.run(debug=False, host='0.0.0.0', port=port)
|
|
|
|
62 |
print(f"Error loading SentenceTransformer: {e}")
|
63 |
raise
|
64 |
|
65 |
+
def __call__(self, input):
|
66 |
+
if isinstance(input, str):
|
67 |
+
input = [input]
|
68 |
try:
|
69 |
+
embeddings = self.model.encode(input, convert_to_numpy=True).tolist()
|
70 |
return embeddings
|
71 |
except Exception as e:
|
72 |
print(f"Error generating embeddings: {e}")
|
73 |
# Fallback to simple embeddings if needed
|
74 |
+
return [[0.0] * 384 for _ in input]
|
75 |
|
76 |
# Initialize ChromaDB with a persistent directory in a writable location
|
77 |
persistent_dir = os.path.join("/tmp", "chroma_db")
|
|
|
285 |
print(f"Error in /ask_question endpoint: {e}")
|
286 |
return jsonify({"response": "Sorry, an error occurred while generating the response."}), 500
|
287 |
|
|
|
288 |
if __name__ == '__main__':
|
289 |
# Make sure GOOGLE_API_KEY is checked before starting the app
|
290 |
if not GOOGLE_API_KEY:
|
|
|
292 |
else:
|
293 |
# Use port 7860 for Hugging Face Spaces compatibility
|
294 |
port = int(os.environ.get("PORT", 7860))
|
295 |
+
app.run(debug=False, host='0.0.0.0', port=port)
|
296 |
+
|