Spaces:
Runtime error
Runtime error
Commit
·
e50acc4
1
Parent(s):
f14da5e
commit
Browse files
app.py
CHANGED
@@ -92,6 +92,14 @@ def keygen(eval_key):
|
|
92 |
user_id = eval_key[1]
|
93 |
return eval_key[0]
|
94 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
|
96 |
def encode_quantize(test_file, eval_key, encodings):
|
97 |
ugly = ['Machine', 'SizeOfOptionalHeader', 'Characteristics',
|
@@ -133,15 +141,11 @@ def encrypt_encoded_quantize(encodings):
|
|
133 |
fhe_api = FHEModelClient(f"fhe_model", f".fhe_keys/{eval_key}")
|
134 |
fhe_api.load()
|
135 |
|
136 |
-
# Ensure encodings is a NumPy array
|
137 |
if isinstance(encodings, str):
|
138 |
-
|
139 |
-
encodings = eval(encodings)
|
140 |
|
141 |
-
# Ensure it's converted to a NumPy array with the correct dtype
|
142 |
encodings = np.array(encodings, dtype=np.float32)
|
143 |
|
144 |
-
# Check for NaN or Inf values
|
145 |
if np.isnan(encodings).any() or np.isinf(encodings).any():
|
146 |
raise ValueError("Encodings contain NaN or Inf values, which cannot be processed.")
|
147 |
|
|
|
92 |
user_id = eval_key[1]
|
93 |
return eval_key[0]
|
94 |
|
95 |
+
def safe_eval(encodings):
|
96 |
+
try:
|
97 |
+
# Replace newline characters and ensure proper commas are added
|
98 |
+
sanitized = encodings.replace('\n', ',').replace(' ', ',')
|
99 |
+
sanitized = sanitized.replace(',,', ',') # Handle potential double commas
|
100 |
+
return eval(sanitized)
|
101 |
+
except SyntaxError:
|
102 |
+
raise ValueError("Failed to safely parse the encodings string.")
|
103 |
|
104 |
def encode_quantize(test_file, eval_key, encodings):
|
105 |
ugly = ['Machine', 'SizeOfOptionalHeader', 'Characteristics',
|
|
|
141 |
fhe_api = FHEModelClient(f"fhe_model", f".fhe_keys/{eval_key}")
|
142 |
fhe_api.load()
|
143 |
|
|
|
144 |
if isinstance(encodings, str):
|
145 |
+
encodings = safe_eval(encodings)
|
|
|
146 |
|
|
|
147 |
encodings = np.array(encodings, dtype=np.float32)
|
148 |
|
|
|
149 |
if np.isnan(encodings).any() or np.isinf(encodings).any():
|
150 |
raise ValueError("Encodings contain NaN or Inf values, which cannot be processed.")
|
151 |
|