Update app.py
Browse files
app.py
CHANGED
@@ -27,11 +27,17 @@ Built by **Mihir Naik** 🚀
|
|
27 |
)
|
28 |
|
29 |
|
30 |
-
|
|
|
|
|
|
|
31 |
|
32 |
-
|
|
|
|
|
|
|
33 |
|
34 |
-
@app.get("/")
|
35 |
def redirect_to_docs():
|
36 |
"""
|
37 |
Redirects to the FastAPI documentation.
|
@@ -55,6 +61,9 @@ def generate_embeddings_all_MiniLM_L6_V2_model(sentences: List[str]):
|
|
55 |
Returns:
|
56 |
dict: A dictionary containing the embeddings as a JSON-compatible list.
|
57 |
"""
|
|
|
|
|
|
|
58 |
embeddings = all_MiniLM_L6_V2_model.encode(sentences)
|
59 |
return {"embeddings": embeddings.tolist()} # Return embeddings as a JSON-compatible list
|
60 |
|
@@ -70,5 +79,9 @@ def generate_embeddings_intfloat_e5_large_v2_model(sentences: List[str]):
|
|
70 |
Returns:
|
71 |
dict: A dictionary containing the embeddings as a JSON-compatible list.
|
72 |
"""
|
|
|
|
|
|
|
|
|
73 |
embeddings = intfloat_e5_large_v2_model.encode(sentences)
|
74 |
return {"embeddings": embeddings.tolist()}
|
|
|
27 |
)
|
28 |
|
29 |
|
30 |
+
try:
|
31 |
+
all_MiniLM_L6_V2_model = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')
|
32 |
+
except Exception as e:
|
33 |
+
raise RuntimeError("Failed to load the all-MiniLM-L6-v2 model.") from e
|
34 |
|
35 |
+
try:
|
36 |
+
intfloat_e5_large_v2_model = SentenceTransformer('intfloat/e5-large-v2')
|
37 |
+
except Exception as e:
|
38 |
+
raise RuntimeError("Failed to load the intfloat/e5-large-v2 model.") from e
|
39 |
|
40 |
+
@app.get("/", include_in_schema=False)
|
41 |
def redirect_to_docs():
|
42 |
"""
|
43 |
Redirects to the FastAPI documentation.
|
|
|
61 |
Returns:
|
62 |
dict: A dictionary containing the embeddings as a JSON-compatible list.
|
63 |
"""
|
64 |
+
if not sentences:
|
65 |
+
raise ValueError("The input list of sentences must not be empty.")
|
66 |
+
|
67 |
embeddings = all_MiniLM_L6_V2_model.encode(sentences)
|
68 |
return {"embeddings": embeddings.tolist()} # Return embeddings as a JSON-compatible list
|
69 |
|
|
|
79 |
Returns:
|
80 |
dict: A dictionary containing the embeddings as a JSON-compatible list.
|
81 |
"""
|
82 |
+
|
83 |
+
if not sentences:
|
84 |
+
raise ValueError("The input list of sentences must not be empty.")
|
85 |
+
|
86 |
embeddings = intfloat_e5_large_v2_model.encode(sentences)
|
87 |
return {"embeddings": embeddings.tolist()}
|