Thomas Chardonnens commited on
Commit ·
581d428
1
Parent(s): 5c8d2eb
aled
Browse files158 unmodified lines1591601611621631641656 unmodified lines172173174175176177178179180181182183184185186187188189190148 unmodified lines339340341342343344345158 unmodified linesimport numpy as np# Resize image if necessaryif input_image.shape != (32, 32, 3):input_image_pil = Image.fromarray(input_image)input_image_pil = input_image_pil.resize((32, 32))input_image = np.array(input_image_pil)6 unmodified linesinput_image = (input_image / 255.0 * 4095 - 2048).astype(np.int16)input_image = np.clip(input_image, -2048, 2047)# Retrieve the client APIclient = get_client(user_id)# Pre-process, encrypt and serialize the imageencrypted_image = client.encrypt_serialize(input_image)# Save encrypted_image to bytes in a file, since too large to pass through regular Gradio# buttons, https://github.com/gradio-app/gradio/issues/1877encrypted_image_path = get_client_file_path("encrypted_image", user_id)with encrypted_image_path.open("wb") as encrypted_image_file:encrypted_image_file.write(encrypted_image)# Get a short representation of the encrypted image for display purposesencrypted_image_short = encrypted_image[:100] # Take first 100 bytes148 unmodified linesgr.Markdown("## Client side")gr.Markdown("### Step 1: Upload an EEG image. ")gr.Markdown(f"The image will automatically be resized to shape (224x224). ""The image here, however, is displayed in its original resolution.")with gr.Row():158 unmodified lines1591601611621631641656 unmodified lines172173174175176177178179180181182183184185186187188189190191192193194195196197198199148 unmodified lines348349350351352353354158 unmodified linesimport numpy as np# Resize image if necessaryif input_image.shape != (32, 32, 1):input_image_pil = Image.fromarray(input_image)input_image_pil = input_image_pil.resize((32, 32))input_image = np.array(input_image_pil)6 unmodified linesinput_image = (input_image / 255.0 * 4095 - 2048).astype(np.int16)input_image = np.clip(input_image, -2048, 2047)print("Processing the image finished")# Retrieve the client APIclient = get_client(user_id)print("Client retrieved")# Pre-process, encrypt and serialize the imageencrypted_image = client.encrypt_serialize(input_image)print("Encrypted image retrieved")# Save encrypted_image to bytes in a file, since too large to pass through regular Gradio# buttons, https://github.com/gradio-app/gradio/issues/1877encrypted_image_path = get_client_file_path("encrypted_image", user_id)print("Encrypted image path retrieved")with encrypted_image_path.open("wb") as encrypted_image_file:encrypted_image_file.write(encrypted_image)print("Encrypted image file retrieved")# Get a short representation of the encrypted image for display purposesencrypted_image_short = encrypted_image[:100] # Take first 100 bytes148 unmodified linesgr.Markdown("## Client side")gr.Markdown("### Step 1: Upload an EEG image. ")gr.Markdown(f"The image will automatically be resized to shape (32, 32). ""The image here, however, is displayed in its original resolution.")with gr.Row():
app.py+11-2