Spaces:
Runtime error
Runtime error
Commit
·
6589f0e
1
Parent(s):
d1b5444
commit
Browse files
app.py
CHANGED
@@ -99,21 +99,21 @@ def safe_eval(encodings):
|
|
99 |
|
100 |
# Replace newline characters and multiple spaces
|
101 |
sanitized = encodings.replace('\n', ',').replace(' ', '')
|
102 |
-
# Remove
|
103 |
-
sanitized = sanitized.replace(',,', ',')
|
104 |
|
105 |
-
#
|
106 |
-
if sanitized.
|
107 |
-
sanitized = sanitized
|
|
|
|
|
108 |
|
109 |
-
# Debugging: Print the sanitized string
|
110 |
print("Sanitized Encodings String:", sanitized)
|
111 |
|
112 |
-
# Use eval to convert the string to a list or array
|
113 |
return eval(sanitized)
|
114 |
except SyntaxError as e:
|
115 |
raise ValueError(f"Failed to safely parse the encodings string: {e}")
|
116 |
|
|
|
117 |
def encode_quantize(test_file, eval_key, encodings):
|
118 |
ugly = ['Machine', 'SizeOfOptionalHeader', 'Characteristics',
|
119 |
'MajorLinkerVersion', 'MinorLinkerVersion', 'SizeOfCode',
|
@@ -155,11 +155,10 @@ def encrypt_encoded_quantize(encodings):
|
|
155 |
fhe_api.load()
|
156 |
|
157 |
encodings = encodings[0]
|
158 |
-
|
159 |
-
if isinstance(encodings, str):
|
160 |
-
encodings = safe_eval(encodings)
|
161 |
|
162 |
-
encodings
|
|
|
|
|
163 |
|
164 |
if np.isnan(encodings).any() or np.isinf(encodings).any():
|
165 |
raise ValueError("Encodings contain NaN or Inf values, which cannot be processed.")
|
|
|
99 |
|
100 |
# Replace newline characters and multiple spaces
|
101 |
sanitized = encodings.replace('\n', ',').replace(' ', '')
|
102 |
+
sanitized = sanitized.replace(',,', ',') # Remove accidental double commas
|
|
|
103 |
|
104 |
+
# Ensure the string starts and ends properly for evaluation
|
105 |
+
if not sanitized.startswith("["):
|
106 |
+
sanitized = "[" + sanitized
|
107 |
+
if not sanitized.endswith("]"):
|
108 |
+
sanitized = sanitized + "]"
|
109 |
|
|
|
110 |
print("Sanitized Encodings String:", sanitized)
|
111 |
|
|
|
112 |
return eval(sanitized)
|
113 |
except SyntaxError as e:
|
114 |
raise ValueError(f"Failed to safely parse the encodings string: {e}")
|
115 |
|
116 |
+
|
117 |
def encode_quantize(test_file, eval_key, encodings):
|
118 |
ugly = ['Machine', 'SizeOfOptionalHeader', 'Characteristics',
|
119 |
'MajorLinkerVersion', 'MinorLinkerVersion', 'SizeOfCode',
|
|
|
155 |
fhe_api.load()
|
156 |
|
157 |
encodings = encodings[0]
|
|
|
|
|
|
|
158 |
|
159 |
+
# Ensure encodings is a proper NumPy array
|
160 |
+
if isinstance(encodings, str):
|
161 |
+
encodings = np.fromstring(encodings.strip("[]"), sep=',', dtype=np.float32)
|
162 |
|
163 |
if np.isnan(encodings).any() or np.isinf(encodings).any():
|
164 |
raise ValueError("Encodings contain NaN or Inf values, which cannot be processed.")
|