Thomas Chardonnens
commited on
Commit
·
581d428
1
Parent(s):
5c8d2eb
aled
Browse files
app.py
CHANGED
@@ -159,7 +159,7 @@ def encrypt(user_id, input_image):
|
|
159 |
|
160 |
import numpy as np
|
161 |
# Resize image if necessary
|
162 |
-
if input_image.shape != (32, 32,
|
163 |
input_image_pil = Image.fromarray(input_image)
|
164 |
input_image_pil = input_image_pil.resize((32, 32))
|
165 |
input_image = np.array(input_image_pil)
|
@@ -172,19 +172,28 @@ def encrypt(user_id, input_image):
|
|
172 |
input_image = (input_image / 255.0 * 4095 - 2048).astype(np.int16)
|
173 |
input_image = np.clip(input_image, -2048, 2047)
|
174 |
|
|
|
175 |
# Retrieve the client API
|
176 |
client = get_client(user_id)
|
177 |
|
|
|
|
|
178 |
# Pre-process, encrypt and serialize the image
|
179 |
encrypted_image = client.encrypt_serialize(input_image)
|
180 |
|
|
|
|
|
181 |
# Save encrypted_image to bytes in a file, since too large to pass through regular Gradio
|
182 |
# buttons, https://github.com/gradio-app/gradio/issues/1877
|
183 |
encrypted_image_path = get_client_file_path("encrypted_image", user_id)
|
184 |
|
|
|
|
|
185 |
with encrypted_image_path.open("wb") as encrypted_image_file:
|
186 |
encrypted_image_file.write(encrypted_image)
|
187 |
|
|
|
|
|
188 |
# Get a short representation of the encrypted image for display purposes
|
189 |
encrypted_image_short = encrypted_image[:100] # Take first 100 bytes
|
190 |
|
@@ -339,7 +348,7 @@ with demo:
|
|
339 |
gr.Markdown("## Client side")
|
340 |
gr.Markdown("### Step 1: Upload an EEG image. ")
|
341 |
gr.Markdown(
|
342 |
-
f"The image will automatically be resized to shape (
|
343 |
"The image here, however, is displayed in its original resolution."
|
344 |
)
|
345 |
with gr.Row():
|
|
|
159 |
|
160 |
import numpy as np
|
161 |
# Resize image if necessary
|
162 |
+
if input_image.shape != (32, 32, 1):
|
163 |
input_image_pil = Image.fromarray(input_image)
|
164 |
input_image_pil = input_image_pil.resize((32, 32))
|
165 |
input_image = np.array(input_image_pil)
|
|
|
172 |
input_image = (input_image / 255.0 * 4095 - 2048).astype(np.int16)
|
173 |
input_image = np.clip(input_image, -2048, 2047)
|
174 |
|
175 |
+
print("Processing the image finished")
|
176 |
# Retrieve the client API
|
177 |
client = get_client(user_id)
|
178 |
|
179 |
+
print("Client retrieved")
|
180 |
+
|
181 |
# Pre-process, encrypt and serialize the image
|
182 |
encrypted_image = client.encrypt_serialize(input_image)
|
183 |
|
184 |
+
print("Encrypted image retrieved")
|
185 |
+
|
186 |
# Save encrypted_image to bytes in a file, since too large to pass through regular Gradio
|
187 |
# buttons, https://github.com/gradio-app/gradio/issues/1877
|
188 |
encrypted_image_path = get_client_file_path("encrypted_image", user_id)
|
189 |
|
190 |
+
print("Encrypted image path retrieved")
|
191 |
+
|
192 |
with encrypted_image_path.open("wb") as encrypted_image_file:
|
193 |
encrypted_image_file.write(encrypted_image)
|
194 |
|
195 |
+
print("Encrypted image file retrieved")
|
196 |
+
|
197 |
# Get a short representation of the encrypted image for display purposes
|
198 |
encrypted_image_short = encrypted_image[:100] # Take first 100 bytes
|
199 |
|
|
|
348 |
gr.Markdown("## Client side")
|
349 |
gr.Markdown("### Step 1: Upload an EEG image. ")
|
350 |
gr.Markdown(
|
351 |
+
f"The image will automatically be resized to shape (32, 32). "
|
352 |
"The image here, however, is displayed in its original resolution."
|
353 |
)
|
354 |
with gr.Row():
|