Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -108,10 +108,17 @@ def encode_quantize_encrypt(text, user_id):
|
|
108 |
if "legal_rating" in model_names:
|
109 |
fhe_api = FHEModelClient(FHE_LEGAL_PATH, f".fhe_keys/{user_id}")
|
110 |
encodings =vectorizer.fit_transform([text]).toarray()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
else:
|
112 |
fhe_api = FHEModelClient(FHE_MODEL_PATH, f".fhe_keys/{user_id}")
|
113 |
encodings = transformer_vectorizer.transform([text])
|
114 |
-
|
115 |
fhe_api.load()
|
116 |
quantized_encodings = fhe_api.model.quantize_input(encodings).astype(numpy.uint8)
|
117 |
encrypted_quantized_encoding = fhe_api.quantize_encrypt_serialize(encodings)
|
|
|
108 |
if "legal_rating" in model_names:
|
109 |
fhe_api = FHEModelClient(FHE_LEGAL_PATH, f".fhe_keys/{user_id}")
|
110 |
encodings =vectorizer.fit_transform([text]).toarray()
|
111 |
+
if dense_matrix.shape[1] < 1736:
|
112 |
+
# 在后面填充零
|
113 |
+
padding = np.zeros((1, 1736 - dense_matrix.shape[1]))
|
114 |
+
dense_matrix = np.hstack((dense_matrix, padding))
|
115 |
+
elif dense_matrix.shape[1] > 1736:
|
116 |
+
# 截取前1736列
|
117 |
+
encodings = dense_matrix[:, :1736]
|
118 |
else:
|
119 |
fhe_api = FHEModelClient(FHE_MODEL_PATH, f".fhe_keys/{user_id}")
|
120 |
encodings = transformer_vectorizer.transform([text])
|
121 |
+
|
122 |
fhe_api.load()
|
123 |
quantized_encodings = fhe_api.model.quantize_input(encodings).astype(numpy.uint8)
|
124 |
encrypted_quantized_encoding = fhe_api.quantize_encrypt_serialize(encodings)
|